Google Groups API - getUsers() You do not have permission to view the member list for the group:

一个人想着一个人 提交于 2019-12-13 18:45:47

问题


Cheers Everyone!

I have a Google script which checks if e-mail addresses are members of a group or not by using getUsers() function.

So far:

  • I have activated "Admin SDK Directory Service"
  • I have admin authority

For most of the groups it does it's magic, however I get authorization error in case of some groups.

Error message from Log:

  • "You do not have permission to view the member list for the group: foo@bar"

Any idea what might be the problem? Anything is very much appreciated. Thank you!


回答1:


The problem is that the GroupsApp service uses the permissions of the GROUP to determine whether or not you can view the members list. The default setting for groups is to restrict this access to owners and managers of the group. So you have two options:

1) Make yourself an owner or manager of the group OR

2) Use the Admin SDK to check for group membership. The Admin SDK allows any super admin to view the list of users in a group. To find out whether a user is a member of a group, you would need to retrieve the group, then iterate through the members list and then compare each member against the user you are looking for:

 function isMember(groupKey,userKey){
    //groupKey: testGroup@yourdomain.com
    //userKey: userEmail@yourdomain.com 

    var memberList = [];

    //Get the members list from the group
    var response = AdminDirectory.Members.list(groupKey);
    memberList = memberList.concat(response.members);
    while (response.nextPageToken){
      response = AdminDirectory.Members.list(groupKey,{pageToken: response.nextPageToken});
      memberList = memberList.concat(response.members);
    }

    if (memberList.length > 1){

      for (var x in memberList){
        if (memberList[x].email == userKey){return true;}
     }
   }
 }

More info Here



来源:https://stackoverflow.com/questions/30179383/google-groups-api-getusers-you-do-not-have-permission-to-view-the-member-lis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!