Google Android 的 API 丢失 Games.getGamesAuthToken
Google APIs for Android is missing Games.getGamesAuthToken
Google API 的在线 reference Android,显示 [=23] 的 public 方法摘要=]游戏 class 其中包括:
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.
}
在服务器上,将收到的授权码交换为令牌
对 https://www.googleapis.com/oauth2/v4/token
进行 RPC 以交换访问令牌的授权代码。
您必须提供服务器客户端 ID、服务器客户端密码(在您创建服务器客户端 ID 时在开发人员控制台中列出)和授权代码。
在此处查看更多详细信息:https://developers.google.com/identity/protocols/OAuth2WebServer?utm_campaign=play games_discussion_permissions_012316&utm_source=anddev&utm_medium=blog#handlingresponse.
获得访问令牌后,可使用以下方式检索玩家 ID:
www.googleapis.com/games/v1/applications/<app_id>/verify/
使用访问令牌。
在 header 中传递身份验证令牌,如下所示:
“授权:OAuth”
响应值将包含用户的玩家 ID。这是用于该用户的正确玩家 ID。
此访问令牌可用于根据需要进行额外的 server-to-server 调用。
Google API 的在线 reference Android,显示 [=23] 的 public 方法摘要=]游戏 class 其中包括:
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. }
在服务器上,将收到的授权码交换为令牌 对
https://www.googleapis.com/oauth2/v4/token
进行 RPC 以交换访问令牌的授权代码。 您必须提供服务器客户端 ID、服务器客户端密码(在您创建服务器客户端 ID 时在开发人员控制台中列出)和授权代码。 在此处查看更多详细信息:https://developers.google.com/identity/protocols/OAuth2WebServer?utm_campaign=play games_discussion_permissions_012316&utm_source=anddev&utm_medium=blog#handlingresponse.获得访问令牌后,可使用以下方式检索玩家 ID:
www.googleapis.com/games/v1/applications/<app_id>/verify/
使用访问令牌。 在 header 中传递身份验证令牌,如下所示: “授权:OAuth”响应值将包含用户的玩家 ID。这是用于该用户的正确玩家 ID。 此访问令牌可用于根据需要进行额外的 server-to-server 调用。