1
我已切換到OAuth2認證以訪問Adwords API。我想使用服務帳戶,因爲我們的應用程序沒有用戶交互。因此,我在Google API控制檯中爲mcc帳戶創建了一個服務帳戶。並使用:Java中的AdWords API,OAuth2和服務帳戶
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory(new JacksonFactory())
.setServiceAccountId("[email protected]")
.setServiceAccountScopes("https://adwords.google.com/api/adwords/")
.setServiceAccountPrivateKeyFromP12File(file)
.setServiceAccountUser("<MCC Account Email")
.build();
創建憑據。
當我現在儘量讓API調用或只需調用credential.refreshToken()
,我得到:
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "access_denied"
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:303)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:323)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:345)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:526)
..
誰能告訴我,我做錯了還是什麼我已經錯過了做?
您使用哪個adwords Api?我使用: com.google.api的廣告 廣告-lib的 1.14.1 com.google.api的廣告 的AdWords軸 1.14。 1 com.google.http-client 谷歌-HTTP-客戶jackson2 1.14.1-β –
user2265366
2013-04-10 11:53:28
我沒有使用AdWords API。嘗試加載其他一些信息,例如用戶聯繫人或谷歌驅動器文檔,以檢查它是否針對所有API特定的AdWords問題或認證問題。 – 2013-04-10 12:43:46