0

I want to make some kind of hierarchy group tree. For making it, I refer to google admin sdk reference.

but I encountered 1 problem using under code.

Service = build('admin', 'directory_v1', credentials=creds)

groupResults = Service.members().list(groupKey='groupsmail@test.com').execute()

groups = groupResults.get('members', [])
# users = groupResults.get('users', [])

if not groups:
    print('No users in the domain.')
else:
    for group in groups:
        if(group.get('type') == 'USER'):
            email = group.get('email')
            users = Service.users().get(userKey=email).execute()
            print(email, users.get('name').get('fullName'))

this output is

1@test.com user1name 2@test.com user2name ....

but, it's too slow to use. So, I wonder how can get username list using groups id?

I did looking for references but couldn't find it.

Thank you for your answer.

Dan
  • 1

1 Answers1

0

You can retrieve in a single call the members list.

Doing a GET request to https://www.googleapis.com/admin/directory/v1/groups/groupKey/members

where groupKey is the email address of the group OR the groupId. You can optionally filter results by role too.

References:

Get all members

Aerials
  • 4,231
  • 1
  • 16
  • 20