0

首先讓我們來看看完美運行的代碼。這是我們如何建立我們的谷歌API客戶端:Google SignIn無法使用Play遊戲服務啓用,但無法使用

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestEmail() 
       .requestIdToken(AppActivity.this.getResources().getString(R.string.server_client_id)) 
       .build(); 

GoogleSignIn.googleApiClient = new GoogleApiClient.Builder(this) 
       .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .build(); 

那麼這個連接:

// GPGS needs optional apparently, at least it crashes without. 
// Normal (non GPGS) SignIn works either way 
googleApiClient.connect(SIGN_IN_MODE_OPTIONAL); 

然後我們調用登錄。出現疊加,我選擇我的電子郵件,登錄貫穿而所有的罰款:

public static void loginGoogleSDK() 
{ 
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient); 
    GameApplication.getActivity().startActivityForResult(signInIntent, RC_SIGN_IN); 
} 

現在有在谷歌Play遊戲服務登入,頗爲相似,但它總是返回用戶取消錯誤。出現GPGS覆蓋,可以選擇電子郵件,然後它消失還給錯誤:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) 
      .requestEmail() 
      .requestIdToken(AppActivity.this.getResources().getString(R.string.server_client_id)) 
      .build(); 

GoogleSignIn.googleApiClient = new GoogleApiClient.Builder(this) 
      .addApi(Games.API) 
      .addScope(Games.SCOPE_GAMES) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .build(); 

連接和登錄是完全平等的。

用戶取消結果碼,回來這裏:

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    // cancelled = true when using GPGS 
    GameLog.i("On Activity Result called, cancelled? " + (resultCode == RESULT_CANCELED)); 


    // [Other code for handling login....] 


} 

有誰知道是什麼導致了這一點,我們如何能夠得到與谷歌播放遊戲服務的登錄工作?

回答

0

我有一個類似的問題,但從我讀過的,你不能使用Auth.GOOGLE_SIGN_IN_API與Games.API。

+0

查看本指南,這可能是:https://developers.google.com/games/services/android/offline-access – keyboard

1

我的代碼是100%正確的。

我不得不在我的遊戲下的Google Play開發者控制檯的「測試人員」下添加我的電子郵件。

對於Google+ SignIn,這不是必需的,但它適用於遊戲。

相關問題