Android PlusClient实施&得到一个令牌

时间:2013-04-11 13:27:37

标签: android google-api oauth-2.0 google-plus

所以我实现了google plus登录到我的应用程序......我的实现非常接近here给出的示例。我和他之间的最大区别是我有更多的范围,我需要。在构建我的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方法的下线我试图从我的会话中获取一个accessstoken,以便传递到我们的服务器,我们在那里做真正的肉和&马铃薯工作。

    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")

这确实产生了一个accessstoken。 YIPPEE!对?不。当我们尝试使用此令牌时,它似乎与我们的应用程序无关。当通过googles 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"
}

author_to值与我们的任何客户端ID都不匹配。根据{{​​3}}的最后一部分,谷歌无法将此令牌请求与我们的项目相匹配。但是,在我们的API控制台中,我确实在那里有用于android的SHA指纹,它确实用分号用分号分隔。没有拼写错误。我等了好几个小时才看出它是否是传播问题。我还添加了SHA指纹以及为我们的调试密钥库创建clientid的东西。我们是否有同样的问题,我们是否从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"
 }
}

因为谷歌出于某种原因没有将该令牌与我的项目相关联。

2 个答案:

答案 0 :(得分:2)

到目前为止,这是谷歌api中的一个错误。

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

答案 1 :(得分:1)

 String accessToken = GoogleAuthUtil.getToken(getActivity(), plusClient.getAccountName(),    
 "oauth2:" + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_PROFILE + " " + MY_SCOPE);

我的代码有效。也许你在“oauth2:”

之后有不必要的标签