Google API -- list all members that are a part of group

73 views Asked by At

Looking for some insight on this task. Want to query all the users that are a part of a group using the Google API Client.

Firstly, I added the proper scopes for my project in OAuth Consent Screen from my google console to be able to query with the correct permissions.
**This is the scope I added ".../auth/admin.directory.group.readonly"

This is what my code looks like:

directory_readonly={"serviceName": "admin", "version": "directory_v1",
                           "scope": ['https://www.googleapis.com/auth/admin.directory.group.readonly']}



creds = Credentials.from_authorized_user_file('token-admin.json',directory_readonly['scope'])



google = googleapiclient.discovery.build(serviceName=directory_readonly['serviceName'],
                                         version=directory_readonly['version'],
                                         credentials=creds)


groupMembers = google.members().list(groupKey="[email protected]").execute()

Reponse:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://admin.googleapis.com/admin/directory/v1/groups/[email protected]/members?alt=json  returned "Request had insufficient authentication scopes.". Details: "[{'message': 'Insufficient Permission', 'domain': 'global', 'reason': 'insufficientPermissions'}]">
0

There are 0 answers