Credential could not be refreshed exception while trying to create a session

83 views
Skip to first unread message

Mohan Upadhyay

unread,
Jun 10, 2018, 8:24:12 PM6/10/18
to AdWords API and Google Ads API Forum
Hi, 
I am trying to download reports using adword api. I am able to do that on my local machine but when I try to establish a session on my remote unix box, I get the following exception,

2018-06-10 13:24:02,326 ERROR [main] com.lendingclub.edh.restful.adaptor.AdwordsRestClient: Failed to create OAuth credentials. Check OAuth settings in the file. Exception: {}
shaded
.com.lendingclub.edh.google.api.ads.common.lib.exception.OAuthException: Credential could not be refreshed.
 at shaded
.com.lendingclub.edh.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:240)
 at com
.lendingclub.edh.restful.adaptor.AdwordsRestClient.connect(AdwordsRestClient.java:98)
 at com
.lendingclub.edh.restful.adaptor.AdwordsLoadAction.run(AdwordsLoadAction.java:91)
 at com
.lendingclub.edh.restful.adaptor.AdwordsLoadAction.main(AdwordsLoadAction.java:48)
 at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java
.lang.reflect.Method.invoke(Method.java:498)
 at org
.apache.oozie.action.hadoop.JavaMain.run(JavaMain.java:56)
 at org
.apache.oozie.action.hadoop.LauncherMain.run(LauncherMain.java:47)
 at org
.apache.oozie.action.hadoop.JavaMain.main(JavaMain.java:35)
 at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java
.lang.reflect.Method.invoke(Method.java:498)
 at org
.apache.oozie.action.hadoop.LauncherMapper.map(LauncherMapper.java:241)
 at org
.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54)
 at org
.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:453)
 at org
.apache.hadoop.mapred.MapTask.run(MapTask.java:343)
 at org
.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:168)
 at java
.security.AccessController.doPrivileged(Native Method)
 at javax
.security.auth.Subject.doAs(Subject.java:422)
 at org
.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
 at org
.apache.hadoop.mapred.YarnChild.main(YarnChild.java:162)
Caused by: java.net.SocketTimeoutException: connect timed out
 at java
.net.PlainSocketImpl.socketConnect(Native Method)
 at java
.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
 at java
.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
 at java
.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
 at java
.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
 at java
.net.Socket.connect(Socket.java:589)
 at sun
.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
 at sun
.net.NetworkClient.doConnect(NetworkClient.java:175)
 at sun
.net.www.http.HttpClient.openServer(HttpClient.java:463)
 at sun
.net.www.http.HttpClient.openServer(HttpClient.java:558)
 at sun
.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
 at sun
.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
 at sun
.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
 at sun
.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
 at sun
.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1022)
 at sun
.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1020)
 at java
.security.AccessController.doPrivileged(Native Method)
 at java
.security.AccessController.doPrivilegedWithCombiner(AccessController.java:782)
 at sun
.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1019)
 at sun
.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
 at sun
.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
 at sun
.net.www.protocol.http.HttpURLConnection.access$100(HttpURLConnection.java:91)
 at sun
.net.www.protocol.http.HttpURLConnection$8.run(HttpURLConnection.java:1283)
 at sun
.net.www.protocol.http.HttpURLConnection$8.run(HttpURLConnection.java:1281)
 at java
.security.AccessController.doPrivileged(Native Method)
 at java
.security.AccessController.doPrivilegedWithCombiner(AccessController.java:782)
 at sun
.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1280)
 at sun
.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
 at shaded
.com.lendingclub.edh.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)
 at shaded
.com.lendingclub.edh.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
 at shaded
.com.lendingclub.edh.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283)
 at shaded
.com.lendingclub.edh.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
 at shaded
.com.lendingclub.edh.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570)
 at shaded
.com.lendingclub.edh.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:248)
 at shaded
.com.lendingclub.edh.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
 at shaded
.com.lendingclub.edh.google.api.ads.common.lib.auth.OAuth2Helper.callRefreshToken(OAuth2Helper.java:69)
 at shaded
.com.lendingclub.edh.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:234)

Please find my implementation attached with the post. The credentials work on my local machine and I am able to retrieve reports. However the code to obtain session fails at new OfflineCredentials.Builder().generateCredential();

Please let me know if I am doing anything wrong.

@Override
   
public void connect() {
       
try {
           
this.logger.info("In connect method");
           
Credential credential = new OfflineCredentials.Builder()
                   
.forApi(Api.ADWORDS)
                   
.withClientSecrets(this.clientId, this.clientSecret)
                   
.withRefreshToken(this.refreshToken)
                   
.build()
                   
.generateCredential();
           
this.logger.info("Connection object created");
           
this.setSession(new AdWordsSession.Builder()
                   
.withDeveloperToken(this.developerToken)
                   
.withOAuth2Credential(credential)
                   
.build());
           
this.logger.info("Successuly established a session");
       
} catch (ValidationException ve) {
           
this.logger.error("Invalid configuration Exception: {}", ve);
       
} catch (OAuthException oe) {
           
this.logger.error("Failed to create OAuth credentials. Check OAuth settings in the file. Exception: {}", oe);
       
}
   
}


AdwordsRestClient.java

Luis Xander Talag (AdWords API Team)

unread,
Jun 11, 2018, 1:58:08 AM6/11/18
to AdWords API and Google Ads API Forum
Hi Mohan,

It seems like your issue is more related to the client library rather than the AdWords API. I suggest to post your issue here as the client library owners are better equipped to assist you here.

Thanks and regards,
Luis
AdWords API Team

Mohan Upadhyay

unread,
Jun 11, 2018, 2:11:03 PM6/11/18
to AdWords API and Google Ads API Forum
For debugging purposes, is there a way to download these reports and make oauth calls using http clients like postman.

Mohan Upadhyay

unread,
Jun 11, 2018, 2:36:43 PM6/11/18
to AdWords API and Google Ads API Forum
Aso is it possible to set a proxy server so that all http(s) calls are made through the proxy server


On Sunday, June 10, 2018 at 5:24:12 PM UTC-7, Mohan Upadhyay wrote:

Luis Xander Talag (AdWords API Team)

unread,
Jun 11, 2018, 10:53:46 PM6/11/18
to AdWords API and Google Ads API Forum
Hi Mohan,

My apologies as we do not support third party client environment like postman. Much better if you could post your issue here as the client library owners might help you with this concern.

Regards,
Luis
AdWords API Team
Reply all
Reply to author
Forward
0 new messages