I have a google apps script attached to a Google Sheets document. I have the following code.
function addGroupMember() {
var userEmail = 'aaa@example.com';
var groupEmail = 'list@mysite.org';
var member = {
email: userEmail,
role: 'MEMBER'
};
member = AdminDirectory.Members.insert(member, groupEmail);
}
function removeGroupMember() {
var userEmail = 'aaa@example.com';
var groupEmail = 'list@mysite.org';
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.