Hello,
You need to store the refresh token and use it for each run. Please see the guide here: https://developers.google.com/adwords/api/docs/guides/authentication -Danial, AdWords API Team. On Saturday, December 13, 2014 3:57:38 AM UTC+3, [email protected] wrote: > > Thanks Danial, > we tried accessing OAuth for API through "Installed Application" > credentials and it worked, but what is the suggested/best way to make calls > from offline java batch jobs to adwords api? > we figured that service accounts are best as they won't need any user > interaction (server to server interactions). > > We are not on Google Apps domain. > > On Friday, November 28, 2014 4:20:14 AM UTC-8, Danial Klimkin wrote: >> >> Hello, >> >> >> First of all, is there any strong reason to use service account? It is >> only available for Google App domains, do you use one? >> >> >> -Danial, AdWords API Team. >> >> >> On Thursday, November 27, 2014 2:48:35 PM UTC+3, [email protected] >> wrote: >>> >>> We tried to create a code to obtain Google Adwords API connection using >>> service account but we are getting the following errors. >>> >>> >>> >>> >>> >>> 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.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken( >>> *GoogleCredential.java:384*) >>> >>> at com.google.api.client.auth.oauth2.Credential.refreshToken( >>> *Credential.java:489*) >>> >>> at >>> com.google.api.ads.common.lib.auth.OAuth2Helper.callRefreshToken( >>> *OAuth2Helper.java:70*) >>> >>> at >>> com.google.api.ads.common.lib.auth.OAuth2Helper.refreshCredential( >>> *OAuth2Helper.java:56*) >>> >>> at >>> com.google.api.ads.common.lib.auth.AuthorizationHeaderProvider.getOAuth2Header( >>> *AuthorizationHeaderProvider.java:102*) >>> >>> >>> >>> >>> >>> >>> >>> *The code for google adwords API connection using service account is :* >>> >>> >>> >>> >>> >>> >>> >>> GoogleCredential serviceAccountCredential = *new* >>> GoogleCredential.Builder() >>> >>> .setTransport(*new* NetHttpTransport.Builder().setProxy(proxy).build()) >>> >>> .setJsonFactory(*new* JacksonFactory()) >>> >>> .setServiceAccountId("****.apps.googleusercontent.com") >>> >>> .setServiceAccountScopes(Collections.*singleton*(" >>> https://adwords.google.com/api/adwords")) >>> >>> .setServiceAccountPrivateKeyFromP12File(keyFile) >>> >>> .setServiceAccountUser("****@gmail.com") >>> >>> .build(); >>> >>> *return* serviceAccountCredential; >>> >>> >>> >>> AdWordsSession adSession = *new* AdWordsSession.Builder() >>> >>> .fromFile() >>> >>> .withOAuth2Credential(credential) >>> >>> .build(); >>> >>> >>> >>> >>> >> -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog and Google+: https://googleadsdeveloper.blogspot.com/ https://plus.google.com/+GoogleAdsDevelopers/posts =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en --- You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. Visit this group at http://groups.google.com/group/adwords-api. To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/0104dd34-3564-4967-8686-75eda6490349%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
