Facing issues while setting up Adword API with Java

55 views
Skip to first unread message

ra...@mistriondoor.com

unread,
Feb 8, 2018, 9:09:29 AM2/8/18
to AdWords API Forum
I am Trying to set up Adwords API through Java, All the steps are going good but in last step while running GetCampaigns.java , Its giving several errors
"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:240) at adwords.axis.v201705.basicoperations.GetCampaigns.main(GetCampaigns.java:46) 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:287) at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:362) at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) at com.google.api.ads.common.lib.auth.OAuth2Helper.callRefreshToken(OAuth2Helper.java:69) at com.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:234) ... 1 more"

Milind Sankeshware (AdWords API Team)

unread,
Feb 8, 2018, 10:52:52 AM2/8/18
to AdWords API Forum
Hi Rahul,

The 'invalid_grant' error is usually noticed when the access token or refresh token is invalid or incorrect. Could you generate a new refresh token with the help of this guide and retry your request? 

To verify that your credentials are correct, you could also try the CURL request provided below and see if you are able to generate the access tokens. If the credentials are correct, you should get an access token for the below request.
curl https://www.googleapis.com/oauth2/v4/token \
-d refresh_token=your-refresh_token \
-d client_id=your-client-id \
-d client_secret=your-client-secret \
-d grant_type=refresh_token

Let me know if the issue persists.

Thanks,
Milind, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages