在线reference对于 Android 版 Google API,显示了 Games 类的公共(public)方法摘要,其中包括:
static PendingResult<Games.GetTokenResult> getGamesAuthToken(GoogleApiClient apiClient)
但最新版本 (8.4.0) 不包含此方法。我用它来获取 API:
dependencies {
compile 'com.google.android.gms:play-services:8.4.0'
}
Games.getGamesAuthToken 在哪里?
最佳答案
这实际上是一个文档问题。 getGamesAuthToken() 已被删除,因为它不够安全。
作为引用,您可以阅读http://android-developers.blogspot.com/2016/01/play-games-permissions-are-changing-in.html
处理此问题的最佳方法是:
播放器在设备上通过身份验证后:
- 获取要发送到后端服务器的授权码:
GetServerAuthCodeResult result = Games.getGamesServerAuthCode(gac, clientId).await(); if (result.isSuccess()) { String authCode = result.getCode(); // Send code to server. }
在服务器上,将收到的授权码交换为 token 对
https://www.googleapis.com/oauth2/v4/token
进行 RPC将授权码交换为访问 token 。 您必须提供服务器客户端 ID、服务器客户端密码(在您创建服务器客户端 ID 时在开发人员控制台中列出)和授权代码。 在此处查看更多详细信息:https://developers.google.com/identity/protocols/OAuth2WebServer?utm_campaign=play games_discussion_permissions_012316&utm_source=anddev&utm_medium=blog#handlingresponse .获得访问 token 后,可以使用以下方法检索玩家的 ID:
www.googleapis.com/games/v1/applications/<app_id>/verify/
使用访问 token 。 在 header 中传递身份验证 token ,如下所示: “授权:OAuth”响应值将包含用户的玩家 ID。这是用于该用户的正确玩家 ID。 此访问 token 可用于根据需要进行额外的服务器到服务器调用。
关于android - 适用于 Android 的 Google API 缺少 Games.getGamesAuthToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36307111/