[英]Adwords API, OAuth2 and service account in Java
I have switched to the OAuth2 authentification for accessing the Adwords API. 我已切换到OAuth2身份验证以访问Adwords API。 I want to use service account, because our application does not have user interaction.
我想使用服务帐户,因为我们的应用程序没有用户交互。 Therefore I created a service account in the Google APIs console for the mcc account.
因此,我在Google API控制台中为mcc帐户创建了一个服务帐户。 And used:
并用于:
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory(new JacksonFactory())
.setServiceAccountId("..@developer.gserviceaccount.com")
.setServiceAccountScopes("https://adwords.google.com/api/adwords/")
.setServiceAccountPrivateKeyFromP12File(file)
.setServiceAccountUser("<MCC Account Email")
.build();
to create the credentials. 创建凭据。
When I now try to make an API call or just call credential.refreshToken()
, I get : 现在,当我尝试进行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)
.. ..
Can anyone tell me, what I am doing wrong or what I have missed doing? 谁能告诉我,我做错了什么或错过了什么?
Can`t say from piece code you posted, i am using exactly same way in my app and everything works fine. 不能说出您发布的邮政编码,我在我的应用程序中使用的方式完全相同,并且一切正常。
My jar versions are : 我的jar版本是:
google-api-services-oauth2-v2-rev9-1.7.2-beta.jar
google-http-client-1.12.0-beta.jar
google-oauth-client-1.12.0-beta.jar
if you are out of ideas try to change version of oauth2 library. 如果您没有主意,请尝试更改oauth2库的版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.