我已切换到 OAuth2 身份验证来访问 Adwords API。我想使用服务帐户,因为我们的应用程序没有用户交互。因此,我在 Google API 控制台中为 mcc 帐户创建了一个服务帐户。并使用:
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();
创建凭据。
当我现在尝试进行 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)
..
谁能告诉我,我做错了什么或者我错过了什么?