AdminDirectory.Members.list Authorization error

落爺英雄遲暮 提交于 2019-12-06 07:37:46

Basically, this script has two issues.

Not Authorized to access this resource/api -> This has at least two possible causes:

a) You don't have sufficient Admin privileges to access this API (Basically, you're not a SuperAdmin).

b) The domain is spelled incorrectly in your live code (I hesitate to even mention this one, but mistakes do happen).

Otherwise, this part works fine for me 'As is' and I can only reproduce the:

Not Authorized to access this resource/api

when one of these two issues apply.

Once you resolve this error, you'll hit a 'Bad Request' for:

membersPage = AdminDirectory.Members.list(group, {
        maxResults: 100,
        pageToken: membersPageToken
      });

Around line 21.

This is because the line:

    var group = groups[i];

Looks like it's just returning a string with the name of the group, but in actually it's returning something like:

{id=GROUPID, nonEditableAliases=[GROUPEMAIL, GROUPEMAIL], etag=GROUPTAG, email=GROUPEMAIL, directMembersCount=3, description=, adminCreated=true, name=GROUPNAME, kind=admin#directory#group}

This is a simple fix, we just replace this with:

      membersPage = AdminDirectory.Members.list(group.email, {
        maxResults: 100,
        pageToken: membersPageToken
      });

And it will return the results we're looking for.

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