Reputation: 161
I have a google apps script attached to a Google Sheets document. I have the following code.
function addGroupMember() {
var userEmail = '[email protected]';
var groupEmail = '[email protected]';
var member = {
email: userEmail,
role: 'MEMBER'
};
member = AdminDirectory.Members.insert(member, groupEmail);
}
function removeGroupMember() {
var userEmail = '[email protected]';
var groupEmail = '[email protected]';
var member = {
email: userEmail,
role: 'MEMBER'
};
member = AdminDirectory.Members.remove(member, groupEmail);
}
The first function works fine to add group members. The second function to delete group members throws the exception "Not Authorized to access this resource/api". I am executing this as an administrator user and I can edit all Google Groups with no problem through the admin UI. What else do I need to get authorized to execute this script?
As far as I can tell, I followed the steps to create authorization on the notes section here - https://developers.google.com/apps-script/advanced/admin-sdk-directory.
My goal is to parse emails from my spreadsheet and use the functions to add/remove members from my Google Groups.
Upvotes: 0
Views: 1375
Reputation: 161
KRR provided the correct answer in his comment. The parameters were not passed correctly. Pasting his comment here.
Maybe this is because the 'remove' method of Members Resource takes 'groupKey' and 'memberKey' as parameters. The method signature is: AdminDirectory.Members.remove(String groupKey, String memberKey). Hope that helps!
Upvotes: 1