本文介绍了Google Admin SDK Directory API中的members.list()(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码(使用Java)可以列出个人Google Apps域中所有组的成员。这使用谷歌目录API。



以下是代码片段:

  public static void listMembers(String groupKey,Directory service)throws IOException {
Members res = service.members()。list(groupKey).execute();

列表<成员> members = res.getMembers();
int count = 0;
if(members == null || members.size()== 0){
System.out.println();
System.out.println(找不到成员);
} else {
System.out.println();
System.out.println(+ groupKey的成员);
(会员会员:会员){
count ++;
System.out.println(member.getEmail());
}
System.out.println(count);




$ b $ p
$ b

这可以正常工作,但对于任何组,比精确的200个成员被列出,尽管一个组实际上拥有更多的用户。我试图搜索我正在使用的 members.list()函数的限制,但在Google文档中找不到Directory API的限制。有没有这种限制?如果是的话,我可以以某种方式列出所有用户吗?

解决方案

查看。页面没有指定,但我相信200既是maxResults的默认值,也是最大值。您的应用需要检查结果中是否存在pageToken属性。如果已设置,您至少还有一页结果要抓取。保持结果循环,直到pageToken未设置。


I have a piece of code(in Java) to list all members of a group on a personal Google Apps Domain. This uses the google Directory API.

Here is the snippet:

public static void listMembers(String groupKey,Directory service) throws IOException {
        Members res = service.members().list(groupKey).execute();

        List<Member> members = res.getMembers();
        int count = 0;
        if (members == null || members.size() == 0) {
            System.out.println();
            System.out.println("No members found.");
        } else {
            System.out.println();
            System.out.println("Members of "+groupKey);
            for (Member member : members) {
                count++;
                System.out.println(member.getEmail());
            }
            System.out.println(count);
        }
    }

This works fine, but for any group, not more than exactly 200 members are listed, though a group actually has more users. I tried to search for the limit on the members.list() function that I am using, but couldn't find it on the Google Documentation for the Directory API. Is there any such limit? If yes, can I somehow list all users?

解决方案

Take a look at the maxResults and pageToken attributes on members.list(). The page doesn't specify but I believe 200 is both the maxResults default value and maximum. Your app needs to check for the existence of the pageToken attribute in the results. If it's set, you have at least one more page of results to grab. Keep looping through results until pageToken is not set.

这篇关于Google Admin SDK Directory API中的members.list()(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 08:03