0

Google Apps For Businessドメインで利用できるグループ(およびそのメンバー)を列挙したいのですが、関連するAPIを見つけるのに問題があります。ドキュメントページで利用できるものはすべて、私がすでにグループ名を知っていることを前提としているようです。それでも、メンバーを一覧表示する方法はありません。

以前のバージョンのAPIであるgdataは、私がやろうとしていることすべてに対して明確なインターフェースを備えていますが、Mavenパッケージを提供していません(実際、そのようなパッケージは提供されないと明示的に述べています)。開発チームは次のことを提案しています。新しいインターフェースが望ましいです。

では、GDATA APIで可能だったのと同じ方法で、Google APIを使用してグループを列挙することは可能ですか?

4

1 に答える 1

0

私はついにこれを行う方法を見つけました。認証を含む基本コード:

public class GroupLister {
    static HttpTransport transport = new NetHttpTransport();
    static HttpParser parser = new AtomParser(new XmlNamespaceDictionary());

    public GroupFeed listGroups(String domainName, String apiKey,
            String username, String password) throws IOException {
        HttpRequestFactory factory = createRequestFactory(transport, username,
                password);
        GoogleUrl url = new GoogleUrl(
                "https://apps-apis.google.com/a/feeds/group/2.0/" + domainName);
        url.key = apiKey;
        return factory.buildGetRequest(url).execute().parseAs(GroupFeed.class);
    }

    public HttpRequestFactory createRequestFactory(
            final HttpTransport transport, final String username,
            final String password) {
        return transport.createRequestFactory(new HttpRequestInitializer() {
            public void initialize(HttpRequest request) throws IOException {
                request.addParser(parser);
                ClientLogin authenticator = new ClientLogin();
                authenticator.transport = transport;
                authenticator.authTokenType = "apps";
                authenticator.username = username;
                authenticator.password = password;
                request.getHeaders().setAuthorization(
                        authenticator.authenticate()
                                .getAuthorizationHeaderValue());
            }
        });
    }

}

データクラス:

public class GroupFeed {
    @Key
    public Date updated;
    @Key("entry")
    public List<GroupEntry> groups;
}

public class GroupEntry {
    @Key
    public String id;
    @Key("apps:property")
    public List<PropertyEntry> properties;
}

public class PropertyEntry {
    @Key("@name")
    public String name;
    @Key("@value")
    public String value;
}

これには多くの試行錯誤が必要でした。

于 2011-11-23T16:08:32.830 に答える