'For Google Workspace, I am trying to get the a list together of all the users' other contacts in my domain

I want to get the "Other Contacts" List for all users in my domain. I can currently get my user's "Other Contacts" list with the following:

results = service.otherContacts().list(
        readMask="names,emailAddresses").execute()

But is there a way to get other users' lists as well?



Solution 1:[1]

If you already can get your 'Other contacts' with that code, all you need to implement is user impersonation in your code, something like:

from googleapiclient.discovery import build
from google.oauth2 import credentials, service_account
 
SCOPES = [Your Scopes list]

# Service Account Credentials to be used. How to create at https://developers.google.com/workspace/guides/create-credentials#service-account
SERVICE_ACCOUNT_FILE = 'yourServiceAccountCredentials.json'

credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes= SCOPES)
delegated_creds = credentials.with_subject('[email protected]')

And since you are using Google Workspace after you create your Service Account and generate the JSON file key you will need to configure Domain Wide Delegation using the client ID of your Service Account plus the scopes you will use.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yancy Godoy