【发布时间】:2016-03-16 12:09:00
【问题描述】:
我正在尝试为我的项目获取 GoogleCredential,如下所示,
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("xxx@famous-store-115417.iam.gserviceaccount.com")
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(new File(p12))
.build();
但我遇到了错误,
Exception in thread "main" com.google.gdata.util.AuthenticationException: Failed to refresh access token: 400 Bad Request
{
"error" : "invalid_grant"
}
at com.google.gdata.client.GoogleAuthTokenFactory$OAuth2Token.refreshToken(GoogleAuthTokenFactory.java:260)
at com.google.gdata.client.GoogleAuthTokenFactory.handleSessionExpiredException(GoogleAuthTokenFactory.java:702)
at com.google.gdata.client.GoogleService.handleSessionExpiredException(GoogleService.java:738)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:649)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
at ImportAwards.openFeed(ImportAwards.java:49)
at ImportAwards.importAwards(ImportAwards.java:62)
at ImportAwards.main(ImportAwards.java:29)
Caused by: com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant"
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
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 com.google.gdata.client.GoogleAuthTokenFactory$OAuth2Token.refreshToken(GoogleAuthTokenFactory.java:258)
... 7 more
我知道这是权限相关的错误,但我使用的是正确的密钥和服务帐户 ID,并且我也通过网络搜索过它,但它与建议的解决方案相同。我也推荐了this。
任何建议都非常感谢,在此先感谢。我应该错过什么?
【问题讨论】:
-
有解决办法吗?
-
请参阅下面的答案,如果它适合您,请投票赞成:)