google-apps-scriptgroup

How to list the members of a Group using google script


I have a group called 'library' with an email address similar to 'library@blowsomewhere.co.uk'. The following code, I believe, should list the members as it is a straight copy (apart from the email address) from the reference documentation:

function listGroupMembers() {
  var myGroup=GroupsApp.getGroupByEmail('library@blowsomewhere.co.uk');
  console.log(group.getEmail() + ':');
  var users = group.getUsers();
  for (var i = 0; i < users.length; i++) {
    var user = users[i];
    console.log(user.getEmail());
  }
}

The error I received was 'an error occurred while looking up roles in the group' at line 2 of the function.

I've checked that the 'Admin SDK API service' is listed under service and authorised it when requested. I authorised it using the same account as actually created the group.


Solution

  • I checked the existing membership of the group and found that the account that is running this script wasn't listed. Having added it as an 'owner' the script now works. This surprised me (but probably shouldn't) as this account is the admin that created the group. Anyway, now working.