Weird OAuth2 failure to refresh access token

2,496 views
Skip to first unread message

Akil Burgess

unread,
Jan 6, 2014, 7:09:32 AM1/6/14
to adwor...@googlegroups.com
Hi All,

We've noticed a weird authentication error that was occurring on one of our application servers over the weekend. All of our MutateJobService.mutate API calls were failing with the error below across multiple accounts. The weird thing is all other API calls were unaffected and the MutateJobService.mutate API calls succeeded across our other application servers (which are all using the same OAuth2 credentials). After restarting the failing application instance the errors disappeared.

Is there a reason why the refresh would only fail for one API call and not for others? Similarly, why would the refresh only fail on one application instance and not others?

Thanks!
Akil Burgess


An unhandled exception occurred.
[Google.Api.Ads.Common.Lib.AdsOAuthException]: Failed to refresh access token.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Google Accounts</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" /><link rel='stylesheet' type='text/css' href='https://ssl.gstatic.com/accounts/o/1893590695-error_page_css_ltr.css'>
<script type="text/javascript" src="https://ssl.gstatic.com/accounts/o/635117462-common_lib.js"></script>
<style>@media screen and (max-width:500px) {#robot {background: none; min-height: 0; min-width: 0; padding: 0;}#stack_trace {display: none;}}
#oauth2_request_info_header {background-image: url("https://ssl.gstatic.com/accounts/o/blank.gif");}</style></head><body ><div id="robot"></div><a href="//www.google.com/" id="googlelogo"><img src="//www.google.com/images/logo_sm.gif" alt="Google"></a><p class="large"><b>403.</b> <ins>That's an error.</ins></p><p class="large">You are not authorized to perform this request.  <ins>That's all we know.</ins></p></body></html>

Stack Trace: 
   at Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessTokenInOfflineMode()
   at Google.Api.Ads.Common.Lib.OAuth2ProviderBase.GetAuthHeader()
   at Google.Api.Ads.AdWords.Lib.AdWordsSoapClient.InitForCall(String methodName, Object[] parameters)
   at Google.Api.Ads.Common.Lib.AdsSoapClient.MakeApiCall(String methodName, Object[] parameters)
   at Google.Api.Ads.AdWords.v201306.MutateJobService.mutate(Operation[] operations, BulkMutateJobPolicy policy)
   ...

Anash P. Oommen (AdWords API Team)

unread,
Jan 6, 2014, 6:00:53 PM1/6/14
to adwor...@googlegroups.com
Hi Akil,

My initial guess is that the page is a rate limit error from the OAuth2 servers (too many instances trying to refresh access token simultaneously). It's a matter of chance that a particular server failed, and the error would go away if the code were retried after a minute or so.

You could reuse the OAuthProvider instance between multiple AdWordsUser instances to reduce its frequency, but could you also open an issue against the AdWords API .NET library to make this code path more robust?

Cheers,
Anash P. Oommen,
AdWords API Advisor.

Akil Burgess

unread,
Jan 7, 2014, 3:57:49 AM1/7/14
to adwor...@googlegroups.com
Hi Anash,

Thanks for your response and the suggestion. We are already reusing OAuthProvider instances do reduce refresh frequency. We had experienced rate limit errors from the OAuth2 servers before (see http://goo.gl/wdDEKU) and the error page was different - is it possible to receive different error pages for rate limit errors?

I've opened Issue #7 (https://github.com/googleads/googleads-adwords-dotnet-lib/issues/7) on the AdWords API .NET library to make the code path more robust.

Cheers,
Akil 

rohit

unread,
Jan 21, 2014, 9:40:25 AM1/21/14
to adwor...@googlegroups.com
Hi,

We are seeing this same error for the past few days using the Ruby client. We make two scheduled attempts to download data at 3:30 AM and 5:30 AM, they both fail with the same error. Manual re-try at 7AM usually succeeds.

ERROR 2014-01-21 03:30:33 21896 [Vulcan::Google]: msg:#<AdsCommon::Errors::AuthError: OAuth2 token refresh failed>
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/auth/oauth2_handler.rb:94:in `refresh_token!'
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/auth/oauth2_handler.rb:83:in `get_token'
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/api.rb:113:in `authorize'

ERROR 2014-01-21 05:30:32 3817 [Vulcan::Google]: msg:#<AdsCommon::Errors::AuthError: OAuth2 token refresh failed>
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/auth/oauth2_handler.rb:94:in `refresh_token!'
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/auth/oauth2_handler.rb:83:in `get_token'
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/api.rb:113:in `authorize'

Any idea what is causing this issue?

Thanks, Rohit

rohit

unread,
Jan 29, 2014, 8:45:35 AM1/29/14
to adwor...@googlegroups.com
Hi,

Can someone from the AdWords team please help with resolving this issue. It has been happening every day for the past 10 days.

ERROR 2014-01-21 03:30:33 21896 [Vulcan::Google]: msg:#<AdsCommon::Errors::AuthError: OAuth2 token refresh failed>
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/auth/oauth2_handler.rb:94:in `refresh_token!'
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/auth/oauth2_handler.rb:83:in `get_token'
/home/offers/tracking/shared/bundle/jruby/1.9/gems/google-ads-common-0.9.3/lib/ads_common/api.rb:113:in `authorize'

Token just prior to failure from this morning.

:issued_at=>2014-01-29 07:41:50 -0600, :expires_in=>3600, :id_token=>nil

Thanks, Rohit

PPC Developer

unread,
Jan 23, 2016, 11:34:08 AM1/23/16
to AdWords API Forum
I'm running into the same problem with the server side. Our platform is essentially a server that runs infinitely to download-process-update ad groups/campigns,etc..the same code runs on multiple server instances on multiple machines. After 1 day or so, some servers start getting the below exception.

Failed to refresh access token
internal_failure

restarting the server instance works, but that means server instances are unable to run for more than 1-2 days and need recycling. Is there any solution to this?

PPC Developer

unread,
Jan 23, 2016, 11:36:45 AM1/23/16
to AdWords API Forum
stack trace for the below error


   at Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessTokenInOfflineMode()
   at Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessToken()
   at Google.Api.Ads.Common.Lib.OAuth2ProviderBase.RefreshAccessTokenIfExpiring()

   at Google.Api.Ads.Common.Lib.OAuth2ProviderBase.GetAuthHeader()
   at Google.Api.Ads.AdWords.Lib.AdWordsSoapClient.InitForCall(String methodName, Object[] parameters)
   at Google.Api.Ads.Common.Lib.AdsSoapClient.MakeApiCall(String methodName, Object[] parameters)
   at Google.Api.Ads.Common.Lib.AdsSoapClient.Invoke(String methodName, Object[] parameters)
   at Google.Api.Ads.AdWords.v201506.ManagedCustomerService.get(Selector serviceSelector)
   at AdwordsReports.Utilities.GetAllMCCAccounts() in c:\Users...mmon.cs:line 919

Anthony Madrigal

unread,
Jan 25, 2016, 11:41:44 AM1/25/16
to AdWords API Forum
Hi,

This seems like this issue is related an internal error with refreshing the access token. In general, if access tokens cannot be refreshed, you should try again after 30 seconds. If this does not work, you should try to do the OAuth2 flow again and get a hold of another access token.

In your App.config file, try setting:
<add key="RetryCount" value="3"/>

If that still does not work, I suggest seeking the help of this forum.

Cheers,
Anthony
AdWords API Team
Reply all
Reply to author
Forward
0 new messages