Intermittent OAUTH_TOKEN_INVALID error

41 views
Skip to first unread message

Latha S

unread,
Apr 29, 2016, 12:29:03 PM4/29/16
to AdWords API Forum
We are getting intermittent OAUTH_TOKEN_INVALID errors, from different AdWords services, which I think occurs when the access token is not automatically refreshed.  After we get the OAUTH_TOKEN_INVALID error, our process continues with the same refresh token and we eventually get a new access token - which seems to indicate that the refresh token is actually valid.  

Is it an issue that we get these intermittent errors?  Is it expected that we will occasionally get an invalid token error?  We do retry (using exponential backoff) for temporary errors, but did not retry an invalid token error assuming that means we needed to generate a new refresh token.  Any help would be appreciated.

Thanks!

Shwetha Vastrad (AdWords API Team)

unread,
Apr 29, 2016, 3:35:13 PM4/29/16
to AdWords API Forum
Hi Latha,

Access tokens have an expiration time. If you are using the token after it has expired, you would get a OAUTH_TOKEN_INVALID error. You should then use the refresh token to get a new access token or to refresh an expired token. If you are using any of the client libraries, by default, the expired access token gets automatically refreshed.

I hope this helps. 

Regards,
Shwetha, AdWords API Team.

Latha S

unread,
Apr 29, 2016, 4:14:20 PM4/29/16
to AdWords API Forum
Thanks for the reply!  

Are you saying that we would not see an "expired token" error when the access token has expired?  I assumed that an invalid token error meant the refresh token was invalid, in which case our code does not continue, expecting that a new refresh token must be generated. I did see in the documentation about the automatic refreshing by the client library, which we use, and since our process continues, I think eventually the automatic refreshing works.

Should we just retry if we get an invalid token error? 

Thank again for your help!

Shwetha Vastrad (AdWords API Team)

unread,
Apr 29, 2016, 4:40:19 PM4/29/16
to AdWords API Forum
Hi Latha,

There are situations where the refresh token might get invalidated. There can be a maximum of 25 valid refresh tokens per application at a time for an account. If this limit is reached, creating a new token automatically invalidates the oldest token without warning. That might be what's happening in your case. You can find more information about refresh tokens here.

Latha S

unread,
May 2, 2016, 10:49:03 AM5/2/16
to AdWords API Forum
Hi Shwetha,

Thanks again for your reply. I apologize if I'm missing something, but it still seems that we are not getting the correct error.

If our refresh token was invalidated (either by exceeding the limit of 25 refresh tokens or something else), then I assume that the refresh token would never succeed in getting an access token.  However, that is not the behavior we see - after getting the invalid token error, later we are able to use the same refresh token, get a valid access token, and get data.  Maybe it's a timing issue, but I think we should get an "expired token" error which we could then retry.  I don't think it's the correct behavior to retry an invalid token error, since that should indicate if the refresh token itself is invalid.

Please let me know if I'm misunderstanding the process. And thank you again for your help in troubleshooting!

Latha



Shwetha Vastrad (AdWords API Team)

unread,
May 2, 2016, 11:10:27 AM5/2/16
to AdWords API Forum
Hi Latha,

Could you provide the SOAP request and response logs for the API requests where you encounter the OAUTH_TOKEN_INVALID error? This will help me determine what's going wrong. Please use Reply privately to author when responding. 

Thanks,
Shwetha, AdWords API Team.

Shwetha Vastrad (AdWords API Team)

unread,
May 16, 2016, 11:58:17 AM5/16/16
to AdWords API Forum
Hi Latha, 

As I mentioned earlier, the client libraries provided for AdWords API automatically refresh the expired access tokens. If you are not using the client libraries, then you need to have a retry logic like you described in your application. 
Reply all
Reply to author
Forward
0 new messages