简体   繁体   中英

Sign-In with google for games services

I am implementing the new sign in with google flow according to this blog post: api-updates-for-sign-in-with-google

However on sign in I get the following exception:

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

I am constructing my GoogleApiClient like this:

final GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this, this)
        .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
        .addApi(Games.API)
        .build();

When I remove .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions) I get the following exceptoin:

java.lang.NullPointerException: Appropriate Api was not requested.

Am I missing something or the new flow does not support Games.API ?

IMO, you can refer to the following sample code:

...
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_games);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();
}

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

@Override
protected void onStop() {
    super.onStop();
    mGoogleApiClient.disconnect();
}


@Override
public void onConnected(Bundle bundle) {
    Log.i("Result", "onConnected");
}

@Override
public void onConnectionSuspended(int i) {
    // Attempt to reconnect
    mGoogleApiClient.connect();
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Log.e("Result", "onConnectionFailed");

    // If the connection failed, in most of time this means user hasn't logined yet
    // In this case invoke the `startResolutionForResult` will launch the login dialog and account picker
    try {
        if (connectionResult.hasResolution()) {
            connectionResult.startResolutionForResult(m_activity, RC_SIGN_IN);
        }
    } catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
    }
}
...

More details at Accessing the Play Games Services APIs in Your Android Game

If your app gets java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information , please read Troubleshooting Issues in Your Android Game

Some screenshots:

在此输入图像描述 在此输入图像描述

There is a similar error that was ask in this community .

The error message seems pretty clear that this isn't possible at the moment: Games has its own login flow. Is there a particular reason you are using both?

Here is a reference on Implementing Sign-in In Your Games .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM