Android的Google APIs缺少Games.getGamesAuthToken [英] Google APIs for Android is missing Games.getGamesAuthToken

查看:385
本文介绍了Android的Google APIs缺少Games.getGamesAuthToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在线参考 for Google for Android for Android ,显示 Games 类的公共方法摘要,其中包括:

  static PendingResult< Games.GetTokenResult> getGamesAuthToken(GoogleApiClient apiClient)

但最新版本(8.4.0)不包含此方法。我使用它来获取API:

 依赖项{
compile'c​​om.google.android.gms:play- services:8.4.0'
}

Games.getGamesAuthToken在哪里?

解决方案

这实际上是一个文档问题。 getGamesAuthToken()已被移除,因为它不像它需要的那样安全。



作为参考,您可以阅读 http://android-developers.blogspot.com/2016/01/play-games-权限不断变化in.html



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

<播放器在设备上进行身份验证后:


  1. 获取授权码以发送到您的后端服务器:

    GetServerAuthCodeResult结果=
    Games.getGamesServerAuthCode(gac,clientId).await();
    if(result.isSuccess()){
    String authCode = result.getCode();
    //将代码发送到服务器。



    $在服务器上,交换由令牌
    收到的授权代码,到 https://www.googleapis.com/oauth2/v4/token 来交换访问令牌的授权码。
    您必须提供服务器客户端ID,服务器客户端密钥(在创建服务器客户端ID时在开发人员控制台中列出)和身份验证代码。
    在此处查看更多详情: https://developers.google.com/identity/protocols/OAuth2WebServer?utm_campaign=play games_discussion_permissions_012316& utm_source = anddev& utm_medium = blog#handlingresponse


  2. 获得访问令牌后,使用以下命令检索玩家ID:
    www.googleapis.com/games/v1/applications/<app_id>/verify / 使用访问令牌。
    在头中传递验证令牌,如下所示:
    授权:OAuth

    响应值将包含用户的玩家ID。这是用于此用户的正确的玩家ID。
    此访问令牌可用于根据需要进行额外的服务器到服务器调用。



The online reference for Google APIs for Android, shows a public method summary for the Games class which includes:

static PendingResult<Games.GetTokenResult> getGamesAuthToken(GoogleApiClient apiClient)

But the latest release available (8.4.0) does not include this method. I use this to get the APIs:

dependencies {    
    compile 'com.google.android.gms:play-services:8.4.0'
}

Where is Games.getGamesAuthToken?

解决方案

This is actually a documentation problem. getGamesAuthToken() has been removed because it was not as secure as it needs to be.

For reference, you can read http://android-developers.blogspot.com/2016/01/play-games-permissions-are-changing-in.html

The best way to handle this is to:

After the player is authenticated on the device:

  1. Get an auth code to send to your backend server: GetServerAuthCodeResult result = Games.getGamesServerAuthCode(gac, clientId).await(); if (result.isSuccess()) { String authCode = result.getCode(); // Send code to server. }
  2. On the server, exchange the auth code received for a token by making an RPC to https://www.googleapis.com/oauth2/v4/token to exchange the auth code for an access token. You’ll have to provide the server client ID, server client secret (listed in the Developer Console when you created the server client ID), and the auth code. See more details here: https://developers.google.com/identity/protocols/OAuth2WebServer?utm_campaign=play games_discussion_permissions_012316&utm_source=anddev&utm_medium=blog#handlingresponse.

  3. Once you have the access token, the player's ID is retrieved using: www.googleapis.com/games/v1/applications/<app_id>/verify/ using the access token. Pass the auth token in a header as follows: "Authorization: OAuth "

    The response value will contain the player ID for the user. This is the correct player ID to use for this user. This access token can be used to make additional server-to-server calls as needed.

这篇关于Android的Google APIs缺少Games.getGamesAuthToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆