问题
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