Credential could not be refreshed, java client library version v201708

847 views
Skip to first unread message

hari krishna

unread,
Sep 20, 2017, 8:36:50 AM9/20/17
to AdWords API Forum
Hi,

 We are getting Credential could not be refreshed error  occasionally. We are using java client library version  v201708.

I generated new refreshToken also but that did not work to solve the issue permanently. 

Can you please help us to resolve this issue permanently. 

Below is the stack trace.

[20 Sep 2017 05:15:42,370-AdwordsDataServicesImpl:ERROR:main] Error in getting AdwordsSession with given credentials
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:229)
at com.aaa.adwords.services.AdwordsDataServicesImpl.generateAdwordsSession(AdwordsDataServicesImpl.java:57)
at com.aaa.adwords.Application.main(Application.java:52)
Caused by: com.google.api.client.auth.oauth2.TokenResponseException: 401 Authorization Required
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:223)
... 2 more

Thanks!
Hari. 

Bharani Cherukuri (AdWords API Team)

unread,
Sep 20, 2017, 3:16:55 PM9/20/17
to AdWords API Forum
Hello Hari,

Could you try and regenerate the refresh token again by following this guide? You can refer to the example from the Java client library for generating the credentials. Additionally, could you confirm if you're generating the refresh token in every API call? If so, please note that there is a limit of 50 refresh tokens per user per account. If you're trying to generate a refresh token above the specified limit, they will be invalidated. Let me know if that works for you.

Thanks,
Bharani, AdWords API Team

hari krishna

unread,
Sep 21, 2017, 2:19:31 AM9/21/17
to AdWords API Forum
Hi Bharani, 

If I generate new refresh token it will work fine. But after couple of days it is not working and i need to generate  new refresh token to make it work. 

I am following below link to generate refresh token. 



below is the code I am using. I am not generating refresh token every time. Once refresh token generated I will keep that in ads.properties( api.adwords.refreshToken=XXXXXXXXXXXXXXXXXXXXXX )

When I start my standalone java application i will call  below method only once. Please let me know is there any thing problem in this. 
 
@Override
public AdWordsSession generateAdwordsSession() {

// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential;
try {
oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build()
.generateCredential();

// Construct an AdWordsSession.
return new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (OAuthException | ValidationException | ConfigurationLoadException e) {
LOGGER.error("Error in getting AdwordsSession with given credentials", e);
return null;
}

}

Thanks!
       Hari. 

Bharani Cherukuri (AdWords API Team)

unread,
Sep 21, 2017, 2:23:07 PM9/21/17
to AdWords API Forum
Hello Hari, 

Your code snippet looks good. To investigate the issue further, could you provide us the logs with complete error message you received with the new refresh token? 

Thanks,
Bharani, AdWords API Team

On Wednesday, September 20, 2017 at 8:36:50 AM UTC-4, hari krishna wrote:

hari krishna

unread,
Sep 22, 2017, 2:16:26 AM9/22/17
to AdWords API Forum
Hi Bharani, 

I have given error message above. Same Error message I am getting.It is not giving any SAOP logs for this call. I only have java error log which i have given below.  Please let me know if you need any other information. Can you please check why Refreshtoken got expired. This refresh token generated few days back and now it is throwing below error (I am using test account.)

 

com.google.api.ads.common.lib.exception.OAuthException: Credential could not be refreshed.
Caused by: com.google.api.client.auth.oauth2.TokenResponseException: 401 Authorization Required



[20 Sep 2017 05:15:42,370-AdwordsDataServicesImpl:ERROR:main] Error in getting AdwordsSession with given credentials
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:229)
at com.aaa.adwords.services.AdwordsDataServicesImpl.generateAdwordsSession(AdwordsDataServicesImpl.java:57)
at com.aaa.adwords.Application.main(Application.java:52)
Caused by: com.google.api.client.auth.oauth2.TokenResponseException: 401 Authorization Required
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:223)
... 2 more



Thanks!
Hari. 

hari krishna

unread,
Sep 22, 2017, 2:24:57 AM9/22/17
to AdWords API Forum
Below property commented out in ads.properties file. Can you Please check is there anything to do with this. 

# Enable/disable automatic OAuth2 token refreshing. Default is enabled.
#api.adwords.refreshOAuth2Token=false 

Thanks!
Hari.

Bharani Cherukuri (AdWords API Team)

unread,
Sep 22, 2017, 1:41:00 PM9/22/17
to AdWords API Forum
Hello Hari, 

To rule out issues with the client library or your ads.properties file, could you issue the access token request via curl as follows?

curl --data "grant_type=refresh_token" \
     --data "refresh_token=YOUR_REFRESH_TOKEN" \
     --data "client_id=YOUR_CLIENT_ID" \
     --data "client_secret=YOUR_CLIENT_SECRET" \

You won't be using curl to get access tokens from your app, but this will tell us if the refresh token, client ID, and client secret you're using are valid. 

Thanks,
Bharani, AdWords API Team


On Wednesday, September 20, 2017 at 8:36:50 AM UTC-4, hari krishna wrote:

hari krishna

unread,
Oct 24, 2017, 10:41:22 PM10/24/17
to AdWords API Forum
Seems this is issue with our proxy server, our proxy server changing the url and that causes this refresh token expire issue. We fixed it in our side. 

Thanks!
Hari. 

Koshish Rijal

unread,
Nov 20, 2019, 2:48:50 AM11/20/19
to AdWords API and Google Ads API Forum


On Wednesday, October 25, 2017 at 8:26:22 AM UTC+5:45, hari krishna wrote:
Seems this is issue with our proxy server, our proxy server changing the url and that causes this refresh token expire issue. We fixed it in our side. 

Thanks!
Hari. 

On Friday, September 22, 2017 at 11:11:00 PM UTC+5:30, Bharani Cherukuri (AdWords API Team) wrote:
Hello Hari, 

To rule out issues with the client library or your ads.properties file, could you issue the access token request via curl as follows?

Hi! I am having similar issue in my server! It works fine in my local machine! Can you please elaborate how you solved? 

Google Ads API Forum Advisor Prod

unread,
Nov 20, 2019, 2:43:48 PM11/20/19
to koshish...@gmail.com, adwor...@googlegroups.com
Hi Koshish, 

Thank you for reaching out to support. Can you make sure that you're using the same set of credentials on both the machines (local and server)? If you could compare the settings used for your local machine with the server settings, it might help you pinpoint the issue. Could you also try the steps followed by Hari on this thread? If you're having an issue, please share the error logs to check this further.

Regards,
Bharani, Google Ads API Team

ref:_00D1U1174p._5001UOCjOu:ref

Samanth goud

unread,
Jul 15, 2020, 6:58:27 AM7/15/20
to AdWords API and Google Ads API Forum
Hi Koshish, 

Even I am facing the same problem (It works fine in my local machine but it fails on server with error= Credential could not be refreshed). Can you please let me the steps to resolve this issue.

Google Ads API Forum Advisor Prod

unread,
Jul 15, 2020, 3:15:26 PM7/15/20
to rome...@gmail.com, adwor...@googlegroups.com
Hi Samanth,

Have you tried all of the solutions from above? If they all do not work, please share logs with me via reply privately to author.

Thanks,
Anthony
Reply all
Reply to author
Forward
0 new messages