Service Account Fail Connection for v201409 ?

248 views
Skip to first unread message

apiapi

unread,
Nov 4, 2014, 4:59:29 PM11/4/14
to adwor...@googlegroups.com

I am using a Service Account with the .NET library for v201402, it has run runs fine without needing OAuth. My code explicitly adds clientCustomerId to every call and does keyword planner API and other API calls without issues.

I updated my code to instead reference the v201409 libraries. When the v18.5 code runs, I get this error from the Adwords API:


Reason:AdsOAuthException.
Google.Api.Ads.Common.Lib.AdsOAuthException: Failed to get access token for service account.
{
 
"error" : "access_denied",
 
"error_description" : "Requested client not authorized."
}
   at
Google.Api.Ads.Common.Lib.OAuth2ProviderForServiceAccounts.GenerateAccessTokenForServiceAccount() in c:\goo\googleads-adwords-dotnet-lib-master18.5\s
rc
\Common\Lib\OAuth2ProviderForServiceAccounts.cs:line 145
   at
Google.Api.Ads.Common.Lib.OAuth2ProviderForServiceAccounts.RefreshAccessToken() in c:\goo\googleads-adwords-dotnet-lib-master18.5\src\Common\Lib\OAut
h2ProviderForServiceAccounts
.cs:line 154
   at
Google.Api.Ads.Common.Lib.OAuth2ProviderBase.RefreshAccessTokenIfExpiring() in c:\goo\googleads-adwords-dotnet-lib-master18.5\src\Common\Lib\OAuth2Pr
oviderBase
.cs:line 249
   at
Google.Api.Ads.Common.Lib.OAuth2ProviderBase.GetAuthHeader() in c:\goo\googleads-adwords-dotnet-lib-master18.5\src\Common\Lib\OAuth2ProviderBase.cs:l
ine
240
   at
Google.Api.Ads.AdWords.Lib.AdWordsSoapClient.InitForCall(String methodName, Object[] parameters) in c:\goo\googleads-adwords-dotnet-lib-master18.5\sr
c
\AdWords\Lib\AdWordsSoapClient.cs:line 61
   at
Google.Api.Ads.Common.Lib.AdsSoapClient.MakeApiCall(String methodName, Object[] parameters) in c:\goo\googleads-adwords-dotnet-lib-master18.5\src\Com
mon
\Lib\AdsSoapClient.cs:line 211
   at
Google.Api.Ads.Common.Lib.AdsSoapClient.Invoke(String methodName, Object[] parameters) in c:\goo\googleads-adwords-dotnet-lib-master18.5\src\Common\L
ib
\AdsSoapClient.cs:line 127
   at
Google.Api.Ads.AdWords.v201409.TrafficEstimatorService.get(TrafficEstimatorSelector selector) in c:\goo\googleads-adwords-dotnet-lib-master18.5\src\A
dWords
\v201409\AdWordsApi.cs:line 20557



What do I need to change to get my Service Account to be recognized/used for v201409? I tried changing the properties of my request header to Version = "v201409" and GroupName = "mcm" and UserAgent ="mycustomstring" and DeveloperToken = "mydevtoken" but things are still unauthorized.

I can run v201402 code side-by-side with v201409 code, I only get refused by v201409 code.

Please help?


Thanks.


Josh Radcliff (AdWords API Team)

unread,
Nov 5, 2014, 3:36:19 PM11/5/14
to adwor...@googlegroups.com
Hi,

Just to make sure I'm understanding your setup, are you using the same version of the client library for both your v201406 and your v201409 tests? In other words, does v18.5 work for v201406 but not v201409, or does v18.5 not work for either API version?

Thanks,
Josh, AdWords API Team

apiapi

unread,
Nov 13, 2014, 9:58:07 AM11/13/14
to adwor...@googlegroups.com
I was using v17 with v201402 and v18.5 with v201409.

It turns out that I needed an additional scope on my Google Apps Engine account set to allow my Adwords account access with the new API version.

Thanks.

Jan Lolling

unread,
Mar 3, 2015, 2:33:18 PM3/3/15
to adwor...@googlegroups.com
I have the same issue with the Java API.
I use the version 1.37.0 of the ads-lib and 1.19.0 for the http-client.

At the moment I use the scope "https://adwords.google.com/api/adwords". Is there any additional scope I have to add?

Best regards
Jan Lolling

Josh Radcliff (AdWords API Team)

unread,
Mar 3, 2015, 4:46:57 PM3/3/15
to adwor...@googlegroups.com
Hi Jan,

That scope has been deprecated, but tokens obtained for it in the past should continue to work. See our Authentication guide for details and for the new, recommended scope.

Were your requests working previously and now fail, or are you trying to submit requests for the first time? If they worked in the past, has anything changed recently such as the version of the API or client library that you are using?

Thanks,
Josh, AdWords API Team

Jan Lolling

unread,
Mar 3, 2015, 5:00:37 PM3/3/15
to adwor...@googlegroups.com
Hi Josh,

yes, I have seen this problem also and changed to the new scope 

https://www.googleapis.com/auth/adwords

I guess there is a problem with the error handling in the method TokenResponseException.from(..)

If the response has no content (InputStream is null, the creation if the exception fails.

I suggest the if condition should be enhanced here like this (see the bold code response.getContent() != null &&

      if (!response.isSuccessStatusCode() && contentType != null && response.getContent() != null &&

         
&& HttpMediaType.equalsIgnoreParameters(Json.MEDIA_TYPE, contentType)) {

        details
= new JsonObjectParser(jsonFactory).parseAndClose(

            response
.getContent(), response.getContentCharset(), TokenErrorResponse.class);

        detailString
= details.toPrettyString();

     
} else {

        detailString
= response.parseAsString();

     
}


This way we should get at least the statusCode and the statusMessage in the case there are no details available. This error toke me about 2 hours to get the problem: status 401 message Not authorized  :-/

Best regards

Jan Lolling 

Jan Lolling

unread,
Mar 3, 2015, 5:06:14 PM3/3/15
to adwor...@googlegroups.com
Additional information to my last post.

I got NullPointerExceptions like this:



java
.lang.NullPointerException

 at com
.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)

 at com
.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127)

 at com
.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:92)

 at com
.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85)

 at com
.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)

 at com
.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:88)

 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 de
.jlo.talendcomp.google.adwords.AdWordsReports.initializeAdWordsSession(AdWordsReports.java:209)

 at
AdWordsTest.main(AdWordsTest.java:34)


My last post suggest a way to avoid this problem and provide a minimum of information.

Josh Radcliff (AdWords API Team)

unread,
Mar 3, 2015, 5:13:42 PM3/3/15
to adwor...@googlegroups.com
Hi Jan,

Thanks for the info. It looks like this is a known issue with the OAuth library:
The AdWords API Team doesn't maintain that lib, but we'll upgrade our pom references once a fix is in.

Thanks,
Josh, AdWords API Team

Reply all
Reply to author
Forward
0 new messages