我得到的错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Invalid Credentials",
"reason" : "authError"
} ],
"message" : "Invalid Credentials"
}
下面的代码,我正在使用:
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(this.TRANSPORT).setJsonFactory(this.JSON_FACTORY)
.setClientSecrets(Constants.CLIENT_ID, Constants.CLIENT_SECRET).build();
credential.setAccessToken(tokenResponse.getAccessToken());
credential.setAccessToken(tokenResponse.getRefreshToken());
到这里,我得到了刷新令牌、访问令牌等
Oauth2 userInfoService = new Oauth2.Builder(this.TRANSPORT,
this.JSON_FACTORY, credential.getRequestInitializer())
.setApplicationName(Constants.APPLICATION_NAME).build();
它在以下行失败:(不知道,为什么?)
Userinfo userInfo = userInfoService.userinfo().get().execute();
我在网上搜索,我得到的例子和稀有材料非常少。任何机构对此有任何想法?
我究竟做错了什么?