0

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.

KRR
  • 4,647
  • 2
  • 14
  • 14
RealDealNeil
  • 151
  • 5
  • 1
    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! – KRR Apr 01 '15 at 16:48
  • So it should be remove(groupEmail, userEmail). – KRR Apr 01 '15 at 16:50
  • The groupKey is the group's unique id, and memberKey is the deleted user or group member's primary email address or the user's unique id. For your reference: https://developers.google.com/admin-sdk/directory/v1/guides/manage-group-members#delete_member – KRR Apr 01 '15 at 17:21
  • Thanks, KRR. The parameters weren't passed correctly! – RealDealNeil Apr 02 '15 at 19:05
  • More group with spreadsheet reference http://stackoverflow.com/questions/27727200/how-to-sync-a-google-groups-membership-with-a-google-spreadsheet/27757928#27757928 – LennyZ71 Apr 03 '15 at 01:45

1 Answers1

1

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!

RealDealNeil
  • 151
  • 5