采用Google Sign-In API验证游戏身份

原标题:Games authentication adopting Google Sign-In API
链接:https://android-developers.googleblog.com/2016/12/games-authentication-adopting-google.html
作者:Clayton Wilkinson (开发者平台工程师)
翻译:arjinmc

Play游戏服务将于2017年初发生一些变化:

Google API客户端构建的更改

11月份,我们宣布了Google Sign-In API的更新。Play游戏服务正在更新,以便使用Google登录API进行身份验证。优点是:

  • 游戏和登录在同一个客户端连接。
  • 获取验证码发送到后端服务器的单一API。

此更改统一了Google登录和游戏API登录,因此有关如何构建Google API客户端的更新:

// Defaults to Games Lite scope, no server component
  GoogleSignInOptions gso = new
     GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build();

// OR for apps with a server component
   GoogleSignInOptions gso = new
     GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
         .requestServerAuthCode(SERVER_CLIENT_ID)
         .build();

// OR for developers who need real user Identity
  GoogleSignInOptions gso = new
     GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
         .requestEmail()
         .build();

// Build the api client.
     mApiClient = new GoogleApiClient.Builder(this)
                .addApi(Games.API)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .addConnectionCallbacks(this)
                .build();
    }

 @Override
    public void onConnected(Bundle connectionHint) {
        if (mApiClient.hasConnectedApi(Games.API)) {
            Auth.GoogleSignInApi.silentSignIn(mApiClient).setResultCallback(
                   new ResultCallback() {
                       @Override
                       public void onResult(GoogleSignInResult googleSignInResult) {
                           // In this case, we are sure the result is a success.
                           GoogleSignInAccount acct = 
                              googleSignInResult.getGoogleSignInAccount());

                          // For Games with a server, send the auth code to your server.
                          String serverAuthCode = signInAccount.getServerAuthCode();

                         // Use the API client as normal.
                        Player player = Games.API.getCurrentPlayer(mApiClient);
                       }
                   }
            );
        } else {
            onSignedOut();
        }
    }

iOS中的帐户创建不再受支持

  • 目前,不支持新玩家在iOS上创建Play游戏帐户。另外,Google+整合已从iOS移除。因此,“社交”API将返回表示成功的结果代码,但返回空列表。这包括排行榜和多人邀请的“标准”用户界面。

Google+不再被整合

我们意识到这是一个巨大的变化,但是前进的Play游戏服务与Google的其他移动平台更加一致,并将为Android游戏开发者带来更好的开发者体验。

results matching ""

    No results matching ""