Error connecting to Google Play Games

825 views Asked by At

OK, I am creating an app with Android studio and I am linking it with Google Game Services. However I am running into a problem.

For some reason, I cannot get my app connected to Google Games. I believe I have done everything correctly. This is the code I currently have:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addApi(Games.API)
            .addScope(Games.SCOPE_GAMES)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

This seems to get caught in a loop where it fails to sign in, then tries to sign in again and again. This is the error I'm getting in the logcat:

GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED,
resolution=PendingIntent{e154144: android.os.BinderProxy@3787b22d}}

However, when I remove the .addApi(Games.API) and .addScope(Games.SCOPE_GAMES) the game connects to Google Plus perfectly!

First, I have created two Client ID's. One for debug and one for release. The SHA1 fingerprints are correct. I have checked and confirmed both that they match. Deep linking is enabled for both. I have added my gmail as a tester. :) When I check the google developer console, it says that there has been 81 request called, and 70 failed. However, it will not tell me which ones failed nor how to fix them. I also have added all the meta-data tags.

Please help and ask me any questions that I left vague. Thank you, Jackson Welch

Update: onActivityResult():

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
  super.onActivityResult(requestCode, resultCode, data);
  switch (requestCode) {
    case REQUEST_CODE_RESOLUTION:
      retryConnecting();
      break;
  }
}

Here is my onConnectionFailed method

 @Override
    public void onConnectionFailed(ConnectionResult result) {
        Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
        if (!result.hasResolution()) {
            // Show a localized error dialog.
            GooglePlayServicesUtil.getErrorDialog(
                    result.getErrorCode(), this, 0, new OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            retryConnecting();
                        }
                    }).show();
            return;
        }

        // If there is an existing resolution error being displayed or a resolution
        // activity has started before, do nothing and wait for resolution
        // progress to be completed.
        if (mIsInResolution) {
            return;
        }
        mIsInResolution = true;
        try {
            result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
        } catch (SendIntentException e) {
            Log.e(TAG, "Exception while starting resolution activity", e);
            retryConnecting();
        }
    }
2

There are 2 answers

2
Jackson Welch On BEST ANSWER

I fixed the problem. I used the old Google Developer Console and the old one will not work. Recreated the project in the new one and it works fine! Thank you guys for your help.

0
ianhanniballake On

Make sure you are following the handling connection failures correctly. Note the onConnectionFailed() example:

@Override
public void onConnectionFailed(ConnectionResult result) {
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (result.hasResolution()) {
        try {
            mResolvingError = true;
            result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
        } catch (SendIntentException e) {
            // There was an error with the resolution intent. Try again.
            mGoogleApiClient.connect();
        }
    } else {
        // Show dialog using GooglePlayServicesUtil.getErrorDialog()
        showErrorDialog(result.getErrorCode());
        mResolvingError = true;
    }
}

This ensures that when you get an error such as SIGN_IN_REQUIRED (which happens to have result.hasResolution() == true, you'll start the appropriate activity needed to resolve the error (i.e., showing the sign in prompt).