title: Client is unauthorized to retrieve access tokens using this method Gmail API
body: <p>As many other people wrote, I encounter the issue as well, I got it while trying to <a href="https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs/patch" rel="noreferrer">set new email signature via the API</a></p>
  
  <p>The exact API call is:</p>
  
  <pre><code>sendAsConfiguration = {
          'signature': 'Test email signature'
      }
  result = gmailService.users().settings().sendAs().patch(userId='xxx@domain.com',
              sendAsEmail="xxx@domain.com",
              body=sendAsConfiguration).execute()
  </code></pre>
  
  <p>The exact response is:</p>
  
  <pre><code>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}')
  </code></pre>
  
  <p>My scenario is as follow:</p>
  
  <ol>
  <li>I'm working with Python from GCP Cloud Functions</li>
  <li>I manage doing requests to the G Suite directory admin, from the same code base and settings</li>
  <li>I made a service account with wild delegation. And I added the right scope both in code and in the G Suite account.</li>
  <li>When trying to work with the gmail API it doesn't work.</li>
  <li>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.</li>
  <li>I repeated all the steps for creating the service account on the original project, it still didn't work.</li>
  </ol>
  
  <p>I need it to work from the production project, and not the test one.</p>
  
  <p>I have read the following questions and answers (and many other variants of them) and nothing worked <a href="https://stackoverflow.com/a/42785468/1020530">answer 1</a>, <a href="https://github.com/googleapis/google-api-python-client/issues/611#issuecomment-454683701" rel="noreferrer">answer 2</a> </p>
  
  <p>Regarding answer 2, I'm not sure I understood this one, so if this the real solution, it would be great getting specific steps.</p>
  
  <p>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</p>
  
  <p><strong>G Suite settings</strong>
  <a href="https://i.stack.imgur.com/Hek3G.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Hek3G.png" alt="G Suite settings"></a>
  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</p>
  
  <p><strong>Service account settings</strong>
  <a href="https://i.stack.imgur.com/S4YEh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/S4YEh.png" alt="enter image description here"></a></p>
  
  <p>Would be great getting help with that,</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I have no OAuth credentials, please see the image below
  <a href="https://i.stack.imgur.com/20Kvz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/20Kvz.png" alt="Credentials"></a></p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>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.</p>
  
  <p>I tried adding to the working account an API key, and it still worked, which gave me more motivation leaving the production settings untouched.</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>I have removed the API keys, it didn't help.</p>
  
  <p>Thanks</p>