Google APIs for Android is missing Games.getGamesAuthToken

泄露秘密 提交于 2019-11-30 21:11:12

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/36307111/google-apis-for-android-is-missing-games-getgamesauthtoken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!