大佬教程收集整理的这篇文章主要介绍了没有额外权限的Android getServerAuthCode(),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
>应用程序调用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.
@H_494_25@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: NeedPermission 04-10 14:27:41.764: W/GamesServerAuthCodeOp(5775): Failed to retrieve the server auth code 04-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的文章).
以上是大佬教程为你收集整理的没有额外权限的Android getServerAuthCode()全部内容,希望文章能够帮你解决没有额外权限的Android getServerAuthCode()所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。