As many other people wrote, I encounter the issue as well, I got it while trying to set new email signature via the API
The exact API call is:
sendAsConfiguration = {
'signature': 'Test email signature'
}
result = gmailService.users().settings().sendAs().patch(userId='xxx@domain.com',
sendAsEmail="xxx@domain.com",
body=sendAsConfiguration).execute()
The exact response is:
google.auth.exceptions.RefreshError: ('unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.', '{\n "error": "unauthorized_client",\n "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."\n}')
My scenario is as follow:
- I'm working with Python from GCP Cloud Functions
- I manage doing requests to the G Suite directory admin, from the same code base and settings
- I made a service account with wild delegation. And I added the right scope both in code and in the G Suite account.
- When trying to work with the gmail API it doesn't work.
- I have created a new project, and deployed the exact same code (with settings of a new service account of course) and all worked well.
- I repeated all the steps for creating the service account on the original project, it still didn't work.
I need it to work from the production project, and not the test one.
I have read the following questions and answers (and many other variants of them) and nothing worked answer 1, answer 2
Regarding answer 2, I'm not sure I understood this one, so if this the real solution, it would be great getting specific steps.
I'm not adding the code itself, since it is working for sure (was tested on an different project, and worked). Please see below the settings of the service account
G Suite settings
At the beginning I had both scopes under the same service account, I got the same result. In the last test I tried each service account having only one scope. Same result
Would be great getting help with that,
UPDATE 1
I have no OAuth credentials, please see the image below
UPDATE 2
I have compared between the project who worked and the one that didn't. The only difference I noticed is, that in the working project there were no API keys. Since people wrote regarding the OAuth, I thought I might give it a chance. But since this is a production environment I don't want to remove them, especially since it was auto generated by Google, and I have no idea where they are being used. I think they aren't used anywhere, but I'm not sure.
I tried adding to the working account an API key, and it still worked, which gave me more motivation leaving the production settings untouched.
UPDATE 3
I have removed the API keys, it didn't help.
Thanks