Token expired message

101 views
Skip to first unread message

trespaan

unread,
Jul 2, 2024, 8:15:42 AMJul 2
to Google Ads API and AdWords API Forum

Hello,

I've built an internal API to retrieve historical metrics for keywords using a Python/Flask application. After thoroughly programming and testing it on my localhost, everything worked perfectly: the client loaded correctly, and metrics were returned as expected.

I then deployed the repository on my Linode server, where the Google Search Console API was already running. Initially, both the search console and Google Ads routes worked fine. However, after five days, the Google Ads route started returning the following error:


```
google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})
```

I've attempted various methods to resolve this issue:

  • Loading the client differently
  • Generating a new refresh token
  • Verifying the API key

Despite these efforts, the application continues to work flawlessly on localhost but not on the Linode server.

Has anyone encountered this problem before or have any suggestions on what to check next?

Thanks!

Google Ads API Forum Advisor

unread,
Jul 2, 2024, 11:04:45 AMJul 2
to tres...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for contacting the Google Ads API support team.

By reviewing your concern, I understand that you're encountering an "invalid_grant" error. According to the Google Ads API documentation, Google Cloud Platform project with an OAuth consent screen configured for an external user type and a publishing status of "Testing" is issued a refresh token expiring in 7 days. Your Google project's publishing status is Testing so the refresh token expires every 7 days and receives an invalid_grant error. 

You can follow the following steps to avoid this issue:
  • Go to the Google API Console and navigate to the OAuth consent screen.
  • Change the publishing status to “In production”.
I hope this helps.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02tJXGg:ref" (ADR-00244770)

Thanks,

 
Google Logo Google Ads API Team

Register for the upcoming workshop: Performance Max and the Google Ads API!
 


trespaan

unread,
Jul 2, 2024, 6:25:18 PMJul 2
to Google Ads API and AdWords API Forum
Hi, 

Thank you for your response!

I just submitted the verification of the app/ consent screen in the Google Cloud Platform, it is worth a shot.
However I don't think this is the problem for the following reasons.

The app worked on the linode server (with proper https protocol) only after some days it stopped working.
If it was due to the app being in 'testing' I can just generate a new token en put that in there and call it a day.
That is not the case. I generated a new token tested it on localhost and it still worked. 
Then when putting it online on the linode server, and then it is giving this error again.

```
google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})
```

I will leave the token in there for now and wait on verification of the consent screen/ scope.
If you have other suggestions please let me know since I cannot find anything online regarding this strange problem.


Thank you in advance,
Trespaan

Google Ads API Forum Advisor

unread,
Jul 2, 2024, 10:54:51 PMJul 2
to tres...@gmail.com, adwor...@googlegroups.com
Hi,

Kindly note that the invalid_grant error usually indicates an issue with the refresh token. That said, you’ll need to regenerate credentials and refresh tokens. Alternatively, you may use the OAuth Playground to generate refresh and access tokens.

trespaan

unread,
Jul 10, 2024, 12:59:53 AMJul 10
to Google Ads API and AdWords API Forum
Hi once again,

I have just passed the verification process for the google ads scope, hoping that that would fix the problem.
It didn't.

I have regenerated OAuth 2.0 Client credential 
Regenerated refresh token for the adwords scope
Regenerated google ads api token
Plugged everything together. 
Test python application on local host and yes there we get the historical metrics. 
Deploy the python  app to the linode and there we go once again an error....

google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'}) 

Why wont this work on a linode server???
I have a normal domain with sub domain where the google search console api connection works fine but the google ads api doesn't.
Its setup with ssh and everything else works fine.

Is there someone that could help. We tried all the tings previously mentioned in this thread...
I can share the code if needed.

Regards,
Trespaan

Google Ads API Forum Advisor

unread,
Jul 10, 2024, 3:00:44 AMJul 10
to tres...@gmail.com, adwor...@googlegroups.com
Hi,

I understand that you have tried all the steps we have provided to resolve the issue, but you are still receiving the error. I would recommend you to reach out to the GCP Product support team for further assistance as they are better equipped to address your concerns.
Reply all
Reply to author
Forward
0 new messages