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 20557https://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
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)