google-workspacegoogle-people-api

Get resourceName's for accounts in a Google Workspace via API


I am superadmin of a Google Workspace. I want to retrieve Google Contacts from several accounts of my workspace (accounts like press@....org, donate@....org).

For doing that via the API call googleapiclient.discovery.build('people', 'v1', credentials=creds).people().connections().list(resourceName=resourceName) I need resourceNames for the accounts of interest.

I tried doing that by running in Python googleapiclient.discovery.build('people', 'v1', credentials=creds).people().listDirectoryPeople(readMask= 'emailAddresses', sources= ['DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE'], pageSize= 1000).execute()). During token retrieval I'm using SCOPES = ['https://www.googleapis.com/auth/contacts.readonly', 'https://www.googleapis.com/auth/directory.readonly'] and re-obtained the creds.

After doing that I received an error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://people.googleapis.com/v1/people:listDirectoryPeople?readMask=emailAddresses&sources=DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE&pageSize=1000&alt=json returned "The G Suite domain admin has disabled external directory sharing. See more details at https://support.google.com/a/answer/6343701". Details: "The G Suite domain admin has disabled external directory sharing. See more details at https://support.google.com/a/answer/6343701">

I went to https://support.google.com/a/answer/6343701 and as recommended switched to Public data and authenticated user basic profile fields in Directory settings. I waited 24 hours, but I'm still getting the same error.

What is the proper way to get resourceNames for the accounts I'm interested in?

In general, am I using the right API calls?

My endgoal is to collect Google Contacts for these accounts. I am superadmin, so I can set up any permissions needed, if I know what is needed :)

Thank you very much!


Solution

  • Answer:

    Enable the contact sharing option in your Directory Settings in the Admin Console. This option is possible for people.listDirectoryPeople for you to be able to list all domain profiles and domain contacts in the authenticated user's domain directory.

    Sample:

    enter image description here

    UPDATE:

    Also, set the External Directory Sharing to Domain and Public Data.

    enter image description here

    You can also test this by running the API Sample on this link

    Showing below that the execution was successful:

    enter image description here