1

Ich versuche, GoogleApiClient mit Games.API und Auth.GOOGLE_SIGN_IN_API zu verbinden (um Benutzerprofilinformationen zu erhalten).
immer diese Fehlermeldung:Auth.GOOGLE_SIGN_IN_API kann nicht mit Games.API verwendet werden

java.lang.IllegalStateException: Auth.GOOGLE_SIGN_IN_API cannot be used with Games.API 

Code:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestProfile() 
       .build(); 

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

Warum ich nicht Games.API mit Auth.GOOGLE_SIGN_IN_API verwenden kann?
Welche Alternative muss ich verbinden Games.API und erhalten Sie Benutzerprofilinformationen?

+0

Haben Sie [diese] (http://stackoverflow.com/questions/35683554/sign-in-with-google-for-games-services) verwiesen. –

+0

@ShreeKrishna es ist das gleiche Problem, aber ich habe nicht die richtige Antwort gefunden ... –

+0

Ich habe ein Problem auf Android-Problem Tracker vorgeschlagen, die neue Google-Login-Flow in Game-API integriert werden: https: // code. google.com/p/android/issues/detail?id=225329 gib ihm einen Stern, wenn du denkst, dass es eine gute Idee ist;) –

Antwort

6

Von mir selbst gelöst.
Sie müssen Auth.GOOGLE_SIGN_IN_API nicht hinzufügen, um Benutzerprofilinformationen abzurufen, wenn Sie bereits Games.API angeschlossen haben.


Connect:

googleApiClient = new GoogleApiClient.Builder(activity) 
       .addConnectionCallbacks(connectionCallbacks) 
       .addOnConnectionFailedListener(onConnectionFailedListener) 
       .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
       .build(); 

Wenn fehlgeschlagen:

@Override 
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 
    if (connectionResult.hasResolution()) { 
     try { 
      connectionResult.startResolutionForResult(this, REQUEST_RESOLVE_ERR); 
     } catch (IntentSender.SendIntentException e) { 
      googleApiClient.connect(); 
      e.printStackTrace(); 
     } 
    } 
} 
@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch (requestCode) { 
     case REQUEST_RESOLVE_ERR: 
      if (resultCode == RESULT_OK) { 
       if (!googleApiClient.isConnecting() 
          && !googleApiClient.isConnected()) 
        googleApiClient.connect(); 
      } 
      break; 
    } 
} 

Wenn angeschlossen:
Get Benutzerprofil Information:

String name = Games.Players.getCurrentPlayer(googleApiClient).getDisplayName(); 
Uri photo = Games.Players.getCurrentPlayer(googleApiClient).getIconImageUri(); 
//and more... 
+0

Aber ohne 'Auth.GOOGLE_SIGN_IN_API' kann ich kein Authentifizierungs-Token bekommen. Ist es möglich? – Alexmelyon

+1

@Alexmelyon ich nehme an nein. Dieses Beispiel dient nur zum Abrufen von Nutzerdaten in Google Games (nicht auf Google+). –

Verwandte Themen