Token expired message

38 views
Skip to first unread message

trespaan

unread,
Jul 1, 2024, 8:15:42 PM (2 days ago) Jul 1
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 1, 2024, 11:04:45 PM (2 days ago) Jul 1
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 AM (18 hours ago) Jul 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 AM (14 hours ago) Jul 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.
Reply all
Reply to author
Forward
0 new messages