android - 适用于 Android 的 Google API 缺少 Games.getGamesAuthToken

标签 android google-play-services google-play-games google-api-client

在线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

处理此问题的最佳方法是:

播放器在设备上通过身份验证后:

  1. 获取要发送到后端服务器的授权码: GetServerAuthCodeResult result = Games.getGamesServerAuthCode(gac, clientId).await(); if (result.isSuccess()) { String authCode = result.getCode(); // Send code to server. }
  2. 在服务器上,将收到的授权码交换为 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 .

  3. 获得访问 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/

相关文章:

android - Gradle 和 proguard : could not find method runProguard() for arguments [true]

具有硬件加速 OpenGL ES 3.0 的 Android 模拟器色带

安卓 : Support in-app updates result getting cancelled

android - Flutter 应用程序在没有静态方法 isAtLeastR 的 Android 10 和 R 上崩溃

android - 更改现有应用程序的证书指纹

android - 具有玩家标准的快速游戏 - 实时多人 Android 谷歌播放服务

android - Android 上的 ffplay

android - 覆盖 Android 上的硬件按钮

android - 如何使用 Google 的 installreferrer 库测试安装引荐来源网址?

android - 如何制作可以访问 Google Play 游戏服务的 ONE