0
votes

I'm getting this error when trying to impersonate a user of a domain who's admin install my app from google apps marketplace.

Client is unauthorized to retrieve access tokens using this method.

The code I'm running:

credentials = service_account.ServiceAccountCredentials.from_json_keyfile_dict(key_data, scopes=REQUIRED_SCOPES) # The key data is generated when creating a service account from my project.
creds = credentials.create_delegated('user1@my_domain.com')
http_client = creds.authorize(Http())
discovery.build('gmail', 'v1', http=http_client)
1

1 Answers

0
votes

To impersonate a user, you must grant the service account access. Also, this error happens when the account that's being impersonated is newly created.

You may check it here: Client is unauthorized to retrieve access tokens using this method Gmail API C#

The service account needs to be authorized or it cant access the emails for the domain.

"Client is unauthorized to retrieve access tokens using this method"

Means that you have not authorized it properly check Delegating domain-wide authority to the service account

Hope this helps!