oAuth2.0 error: Credential could not be refreshed........ client.auth.oauth2.TokenResponseException: 400 Bad Request , "error" : "invalid_grant"

4,998 views
Skip to first unread message

Echo Li

unread,
Jul 31, 2013, 1:37:19 PM7/31/13
to adwor...@googlegroups.com
Hi Gurus,

I was trying to upgrade to oAuth2 authentication from ClientLogin method, when I run the sample code I got below errors, have no clue what caused it, is it possible that the way I create the "clientID" and "ClientSecret" caused it?  any reply is appreciated.....

Exception in thread "main" com.google.api.ads.common.lib.exception.OAuthException: Credential could not be refreshed.
        at com.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:149)
        at DownloadCriteriaReportWithAwql.main(DownloadCriteriaReportWithAwql.java:42)
Caused by: com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "invalid_grant"
}
        at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
        at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:332)
        at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:352)
        at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:535)
        at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:248)
        at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:454)
        at com.google.api.ads.common.lib.auth.OAuth2Helper.callRefreshToken(OAuth2Helper.java:70)
        at com.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:144)


Echo

Takeshi Hagikura (AdWords API Team)

unread,
Aug 2, 2013, 2:33:21 AM8/2/13
to adwor...@googlegroups.com
Hi,

I guesss, it's because the account you granted access to AdWords and the account you were trying to make a request against are different (or not under the MCC you granted access).

Please make sure you grant access to an MCC account or a client account. 
And the account you are trying to make a request is under the MCC or the client account you granted access.

Best,
- Takeshi, AdWords API Team
Message has been deleted

test...@idilia.com

unread,
Jan 16, 2014, 10:41:22 AM1/16/14
to adwor...@googlegroups.com
I had the exact same error message and solved the problem. What I was doing wrong is the following:

When using GetRefreshToken and copying the url in the browser I was copying the code (starting by 4/) obtained by this page as the refreshToken in ads.properties, instead of copying this code back into the (GetRefreshToken) console and using as a refreshToken the one generated by GetRefreshToken (starting by 1/).

I should have paid more attention to the instructions !

Josh Radcliff (AdWords API Team)

unread,
Jan 21, 2014, 11:51:29 AM1/21/14
to adwor...@googlegroups.com
Hi Echo,

If the prior post doesn't solve the issue, please see the following discussion, which covers many of the common issues and questions around configuring your app for OAuth 2.


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