5

所以我实现了谷歌加登录到我的应用程序......我的实现非常接近这里给出的例子。我和他最大的不同是我需要更大的范围。在构建我的 plusclient 时,我指定了以下范围:

    "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo.email"

稍后在我的 onConnected 方法中,我尝试从我的会话中获取一个访问令牌,以便传递给我们的服务器,在那里我们进行真正的肉类和土豆工作。

    GoogleAuthUtil.getToken(SplashActivity.this, mPlusClient.getAccountName(), "oauth2: https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo.email")

这确实产生了一个访问令牌。耶!正确的?不。当我们尝试使用这个令牌时,它似乎与我们的应用程序无关。当通过谷歌的 tokeninfo 端点运行令牌时,我们得到了一些类似的东西

{
 "issued_to": "608941808256-43vtfndets79kf5hac8ieujto8837660.apps.googleusercontent.com",
 "audience": "608941808256-43vtfndets79kf5hac8ieujto8837660.apps.googleusercontent.com",
 "user_id": "107245641469745809180",
 "scope": "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.profile https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo.email",
 "expires_in": 3577,
 "email": "redacted@email.com",
 "verified_email": true,
 "access_type": "online"
}

issue_to 值与我们的任何客户 ID 都不匹配。根据这篇博文的最后一部分,谷歌无法将此令牌请求与我们的项目相匹配。但是,在我们的 API 控制台中,我确实有 SHA 指纹用于 android,并且它确实与包名称用分号分隔。没有拼写错误。我已经等了几个小时,看看这是否是传播问题。我还添加了 SHA 指纹等来为我们的调试密钥库创建一个客户端 ID。无论是从 eclipse 中导出签名的 apk 还是直接运行它,我们都会遇到同样的问题。

这让我发疯。我不知道该转向哪里。

例如,当调用

googleapis.com/plus/v1/people/me/people/visible?access_token=TOKEN_HERE&maxResults=100&pageToken=&alt=json&orderBy=best

我明白了

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured"
   }
  ],
  "code": 403,
  "message": "Access Not Configured"
 }
}

因为无论出于何种原因,谷歌都没有将该令牌与我的项目相关联。

4

2 回答 2

2

到目前为止,这是作为 google api 中的一个错误出现的。

如果我取出“ https://www.google.com/m8/feeds ”范围,那么一切正常,并且令牌与我们的项目成功关联。如果将“ https://www.google.com/m8/feeds ”作为请求的范围包含在内,尽管它会正确提示用户获得该特定权限,但 api 端的一切都会中断。虽然我们在请求这个范围的时候还是会得到一个token,但是这个token并没有和我们的项目相关联。

于 2013-04-11T16:56:35.953 回答
1
 String accessToken = GoogleAuthUtil.getToken(getActivity(), plusClient.getAccountName(),    
 "oauth2:" + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_PROFILE + " " + MY_SCOPE);

我的代码有效。也许你在“oauth2:”之后有不必要的标签

于 2013-04-11T13:40:03.553 回答