如何枚举我域中的 Google 网上论坛并列出其成员?

发布于 2024-12-17 10:37:13 字数 694 浏览 3 评论 0原文

我想枚举我的 Google Apps For Business 域中可用的群组(及其成员),但在查找相关 API 时遇到问题。 文档页面上提供的所有内容似乎都假设我已经知道小组名称 - 即使这样也无法列出成员。

该 API 的早期版本 gdata 具有清晰的界面 用于我打算做的所有事情 - 但它不提供 Maven 包(事实上它明确指出 不会提供此类包)和开发团队表明新界面更可取

那么是否可以使用 Google API 枚举组,就像使用 GDATA API 一样?

I want to enumerate the groups (and their members) that are available on my Google Apps For Business domain, but I am having problems finding relevant API. Everything available on the documentation page seems to assume I already know the group name - and even then there's no way to list the members.

The previous version of the API, gdata, has a clear interface for everything that I intend to do - but it does not provide a Maven package (in fact it explicitly states that no such package will be provided) and the development team is suggesting that the new interface is preferable.

So is it possible to enumerate groups using Google API the same way it was possible with GDATA API?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋日私语 2024-12-24 10:37:13

我终于知道如何做到这一点。基本代码,包括身份验证:

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;
}

这需要大量的试验和验证。错误尝试。

I finally found out how to do this. Basic code, including authentication:

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());
            }
        });
    }

}

Data classes:

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;
}

This took a lot of trial & error attempts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文