【问题标题】:retreive google user info from tokenId从令牌 ID 检索谷歌用户信息
【发布时间】:2017-01-30 15:52:53
【问题描述】:

在我的应用程序中,我将 google 令牌 ID 作为字符串格式的输入。我的问题是,是否可以使用 java google API 检索用户信息,例如(用户名、邮件 ....)。

我试过这个例子

Credential credential = GoogleCredential().setAccessToken(tokenId);
Oauth2 oauth2 = new Oauth2.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
Userinfoplus userinfo = oauth2.userinfo().get().execute();
return userinfo.getEmail();

我收到以下错误:

 com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Insufficient Permission",
    "reason" : "insufficientPermissions"
  } ],
  "message" : "Insufficient Permission"
}

【问题讨论】:

    标签: java oauth-2.0 google-api google-oauth


    【解决方案1】:

    假设您获得了一个 ID 令牌,这可能就是您需要的: https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo

    【讨论】:

      猜你喜欢
      • 2016-01-31
      • 1970-01-01
      • 2015-04-28
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 2016-04-24
      • 2017-10-11
      • 1970-01-01
      相关资源
      最近更新 更多