
>应用程序调用getServerAuthCode()并使用httpS将授权代码转发给我们的BE
> BE使用GoogleAuthorizationCodetokenRequest交换访问令牌的服务器授权代码
> BE将访问令牌传递给www.GoogleAPIs.com/games/v1/applications,后者返回playerID(这是我真正需要的,我不关心电子邮件和其他用户信息)
该程序概述如下:
> https://android-developers.googleblog.com/2016/01/play-games-permissions-are-changing-in.html(2016)
和这里
> https://android-developers.googleblog.com/2016/12/games-authentication-adopting-google.html(2017)
如果我使用2017年的指令,我可以在不请求任何额外权限的情况下获取ServerAuthCode().唯一的权限是:Google Play /管理此游戏的游戏活动.这可以通过使用播放服务10.2.1指定可用的GoogleSignInoptions.DEFAulT_GAMES_SIGN_IN来实现.由于第三方依赖,我无法使用10.2.1.
2016年的文章解释了如何将getServerAuthCode()称为“旧”方式(使用play-services 9.6.1),但是如果没有请求一些额外的权限,我就无法顺利完成.
如果我这样做,我会被问到“知道你是谁在谷歌”:
GoogleSignInoptions gso = new GoogleSignInoptions.Builder(GoogleSignInoptions.DEFAulT_SIGN_IN) .requestServerAuthCode(serverClIEntID) .requestScopes(Games.ScopE_GAMES) .build();mGoogleapiclient = new Googleapiclient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addAPI(Auth.Google_SIGN_IN_API,gso) .build(); ...protected voID onActivityResult(int request,int response,Intent data) { super.onActivityResult(request,response,data); if (request == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInAPI.getSignInResultFromIntent(data); if (result.isSuccess()) { GoogleSignInAccount acct = result.getSignInAccount(); String authCode = acct.getServerAuthCode(); } 如果我从gso中删除.requestServerAuthCode(serverClIEntID),则authCode为null.
我试过的另一件事(仅使用Games.API登录):
mGoogleapiclient = new Googleapiclient.Builder(this,this,this) .addAPI(Games.API) .build();...Games.GetServerAuthCodeResult result = Games.getGamesServerAuthCode(mGoogleapiclient,serverClinetID).await();if (result.getStatus().isSuccess()) { String authCode = result.getCode(); 我得到result.getStatus().isSuccess()= false和result.getStatus().getStatusMessage()返回STATUS_CLIENT_RECONNECT_required(2).在日志中我看到:
[GetToken] GetToken Failed with status code: NeedPermission04-10 14:27:41.764: W/GamesServerAuthCodeOp(5775): Failed to retrIEve the server auth code04-10 14:27:41.764: W/GamesServerAuthCodeOp(5775): com.Google.androID.gms.auth.UserRecoverableAuthException: NeedPermission
Finnaly,我能够实现的最好的目标是获得“仅查看您的基本个人资料信息”权限:
Scope scope = new Scope("https://www.GoogleAPIs.com/auth/userinfo.profile");mGoogleapiclient = new Googleapiclient.Builder(this,this) .addAPI(Games.API) .addScope(scope) .build(); 所以回顾一下 – 我希望使用9.6.1获取服务器授权代码,而不会被提示获得任何额外的权限(例如2017年使用10.2.1使用DEFAulT_GAMES_SIGN_IN的文章).
是否有任何我可以使用的范围将为我提供服务器授权代码(获取playerID)而无需请求额外的权限?
解决方法 很不幸的是,不行.您已经使用的范围是检索身份验证代码并同时获取playerID的正确(也是最简单)方法. 总结以上是内存溢出为你收集整理的没有额外权限的Android getServerAuthCode()全部内容,希望文章能够帮你解决没有额外权限的Android getServerAuthCode()所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)