Google Ads API says “Token has been expired or revoked” despite using a refresh token For Desktop Application

1,270 views
Skip to first unread message

DHARAVATH KARTHIK

unread,
Jul 23, 2021, 3:57:58 AM7/23/21
to AdWords API and Google Ads API Forum
Hi all,

I've set up the whole Google Ads API according to this manual here: https://developers.google.com/google-ads/api/docs/client-libs/python/oauth-desktop?hl=en

I got my refresh token and put it in my google-ads.yaml file which looks exactly like this: https://github.com/googleads/google-ads-python/blob/master/google-ads.yaml. I also put my client_id, developer_token and client_secret at the corresponding spots in the file.

Everything worked out and I tried an example to  get forecast metrics of few keywords campaigns: https://developers.google.com/google-ads/api/docs/keyword-planning/generate-forecast-metrics. Also I could use other services of the API.

Each time I use the API I access it via the client using the following code:

from google.ads.google_ads.client import GoogleAdsClient 
client = GoogleAdsClient.load_from_storage(path_to_google_ads_yaml_file)

As I already said it worked.

A few days later I tried to connect again and I got the following error:

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

So I did the process of getting a new refresh token again (https://developers.google.com/google-ads/api/docs/client-libs/python/oauth-desktop?hl=en) such that everything worked out again.

One day later I got the same error again.  Please someone suggest me the reason for this error.

Google Ads API Forum Advisor

unread,
Jul 26, 2021, 1:19:53 AM7/26/21
to dharavath...@gmail.com, adwor...@googlegroups.com

Hi Karthik,

Thanks for reaching out to us. Kindly note that the invalid_grant usually indicates an issue with the refresh token. That said, you’ll need to regenerate credentials and refresh tokens. You may refer here to this guide for the steps on how you can regenerate credentials and refresh tokens.

Should you continue to encounter issues with the said token, even after following the steps from the above guide, I would recommend that you reach out instead to the Google API Console Support team via this link.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2JD6Ro:ref
Reply all
Reply to author
Forward
0 new messages