How to Validate the RefreshToken programmatically in Google Ads API?

1,418 views
Skip to first unread message

Paid Media

unread,
Mar 21, 2022, 3:41:43 AM3/21/22
to Google Ads API and AdWords API Forum
Hi Team,

We wanted to check if the refresh token that we use while calling Google ads API is valid or not. Because at max we can have 50 refresh token at a time and if we create new 51st refresh token then the oldest one will expire. Which will cause an issue to our customers as making an API call with expired or invalid refresh token is taking lot of time before giving an exception(25 mins approx or even more) and hence causing a 504 TIMEOUT.
Can you please let us know if we can programmatically check its validity and hence log it for notification?  

Regards,
Anurag Sinha

Google Ads API Forum Advisor

unread,
Mar 21, 2022, 10:13:24 AM3/21/22
to paid.m...@gmail.com, adwor...@googlegroups.com
Hi Anurag,

For a method to detect an invalidated refresh token you may reach out to GCP support. With that being said, are there calls with invalidated refresh token that take a split second to error that can be scheduled to test before doing a transaction that takes a long time? I am curious to know if ListAccessibleCustomers takes long.

Regards,

Google Logo
Aryeh
Google Ads API Team
 


ref:_00D1U1174p._5004Q2Ypmvm:ref

Paid Media

unread,
Mar 22, 2022, 12:52:28 AM3/22/22
to Google Ads API and AdWords API Forum
Hi Team,
I tried with ListAccessibleCustomers only and last time when I tried it took 61 mins for giving any exception. 
Regards,
Anurag Sinha

Google Ads API Forum Advisor

unread,
Mar 22, 2022, 6:29:54 AM3/22/22
to paid.m...@gmail.com, adwor...@googlegroups.com

Hi Anurag,

Thanks for getting back to us.

For more details about the refresh token expiration, you may refer to this document from the Google Identity Platform OAuth. However, the access token has an expiration time (based on the expires_in value) after which the token is no longer valid. You can use the refresh token to refresh an expired access token. By default, our client libraries automatically refresh expired access tokens. Also, you may encounter an 'invalid_grant' error whenever the refresh token expires or is not valid in the Google Ads API. you may use the cURL below to check if your refresh token is valid or not:

curl \

  --data "grant_type=refresh_token" \

  --data "client_id=CLIENT_ID" \

  --data "client_secret=CLIENT_SECRET" \

  --data "refresh_token=REFRESH_TOKEN" \

  https://www.googleapis.com/oauth2/v3/token


Let us know if you have any further questions.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2Ypmvm:ref

ashish delacon

unread,
May 1, 2022, 8:43:26 AM5/1/22
to Google Ads API and AdWords API Forum
I am getting the following even though if I use this in uploadconversion, it works fine.
{
    "error": "invalid_client",
    "error_description": "Unauthorized"
}

I want to do the validation so that my uploadconversion doesnt get caught into infinite invalid_grant loop , because for some unknown reason invalid_grant error put the program into infinite loop of invalid_grant

Google Ads API Forum Advisor

unread,
May 3, 2022, 12:33:55 AM5/3/22
to ash...@delaconcorp.com, adwor...@googlegroups.com
Hi Ashish,

Thank you for reaching out to the Google Ads API forum.

With regard to your concern, it would be helpful to check this by providing the complete request and response logs with the request-id generated on your end where we can see the said error. For security purposes you can provide it via Reply privately to the author option. If this option is not available, then send it instead on this email address googleadsapi-support@google.com.

Best regards,
Google Logo
Jinky
Google Ads API Team
 


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