0

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

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)
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
ericls
  • 108
  • 1
  • 5

1 Answers1

0

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!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • Thank for your reply! quote from the docs: "When you use G Suite Marketplace to install an application for your domain, the required permissions are automatically granted to the application. You do not need to manually authorize the service accounts that the application uses." But it doesn't seems to be automatically granted. – ericls May 09 '17 at 16:10