2013-04-11 41 views
5

所以我实施谷歌加登录到我的应用程序...我的执行非常紧密遵循给出的例子here。我和他之间最大的区别是我有一套我需要的范围更大的范围。建设我的plusclient当我指定以下范围:Android 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方法我试图为了从我的会议上得到的accessToken传递到我们的服务器,我们做真正的肉&马铃薯工作。

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

这确实产生了一个accesstoken。 YIPPEE!对?不。当我们尝试并使用此令牌时,似乎它与我们的应用程序无关。通过谷歌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": "[email protected]", 
"verified_email": true, 
"access_type": "online" 
} 

是ISSUED_TO值不与任何我们的客户的id的匹配线的东西。根据this blog post的最后部分,Google无法将此令牌请求与我们的项目匹配。然而,在我们的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 =最好

我得到

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

,因为谷歌因为种种原因没有与我的项目,令牌关联。

+0

这使我疯狂。我似乎无法解决它。 – frostymarvelous 2015-03-18 09:23:47

回答

2

到目前为止,这可能是你在google api中遇到的一个bug。

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

+2

仅适用于其他人,您需要跟踪该网址上的斜杠:“https://www.google.com/m8/feeds/ - 如果没有它,将无法匹配范围,并提供错误。 – 2013-04-19 10:10:24

+0

我真的很感谢你的帮助。哇。我只能说是哇。一个缺少的斜线。哈哈。然而,我认为这是api中的一个错误。当请求这个作用域而没有结尾的斜线时,它会解析并通知那个权限页面中的用户,我们正在请求这个权限,但是这些令牌与我们的应用程序之间的联系中断了......无论如何,谢谢谢谢谢谢:-) – MrTristan 2013-04-19 14:36:25

+0

另外,有趣的是......当你使用或不使用通过该tokeninfo端点的斜线后,它运行的令牌实际上在关联的作用域列表中显示了带和不带斜杠的作用域。也许有两个解决的m8/feed范围? – MrTristan 2013-04-19 14:41:28

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

我的代码有效。 “oauth2:”

+0

是的代码也适用于我...我得到一个accesstoken ....它只是访问令牌不与我们的项目相关联。我可以打电话给“https://www.googleapis.com/oauth2/v1/userinfo?access_token=”,但使用该令牌的任何其他呼叫,正如我上面提到的,产生403 – MrTristan 2013-04-11 13:54:55

+0

哦..您应该添加另一个范围.. – 2013-04-11 14:18:03

+0

我使用的是“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“作为我的示波器 – MrTristan 2013-04-11 14:19:42