1

I have a simple game, with a leaderboard button, it shows the top score of the player, before posting this question, i have made sure about the following :

  1. SHA1 Fingerprint.
  2. APIs enabled.
  3. Correct Package.
  4. Correct App ID.
  5. Google Play Service libs imported and added.
  6. Config file imported.
  7. Admob, Analytics and crash reports are working fine.
  8. GET ACCOUNTS already added, still the same.

My problem is, no Account chooser/picker is showing, and it's not even signing in, im getting the following error :

ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{fbd982b: android.os.BinderProxy@b3d396d}, message=null

Code :

public class MainActivity extends AppCompatActivity implements
    GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

ImageButton mLeaderBoard;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_welcome);
    mLeaderBoard = (ImageButton) findViewById(R.id.leaderboard);
    mLeaderBoard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ShowBoard();
        }
    });

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

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

}

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

private void ShowBoard() {
    if(!isSignedIn()){
        mGoogleApiClient.connect();
    }
    mGoogleApiClient.connect();
    if(isSignedIn())
    startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
            LEADERBOARD_TOP_SCORE_ID), 1);
    else
        Toast.makeText(this, getResources().getString(R.string.leaderboard_not_available), Toast.LENGTH_LONG).show();

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == 1) {

        Log.i("GoogleSignInApi","Result: " + resultCode + " - Data: " + data.getData());
        if (resultCode == RESULT_OK) {

        }
    }
}



@Override
public void onConnected(Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {
    mGoogleApiClient.connect();
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    Log.i("GoogleSignInApi","Problem: " + connectionResult.getErrorMessage() + " - Test: " + connectionResult.toString());
}

 }
Jaeger
  • 1,646
  • 8
  • 27
  • 59

2 Answers2

1

AFAIK, you should have SCOPE_PLUS_PROFILE - OAuth2.0 scope for accessing the user's profile data. You need to enable Google+ API and create Credentials with SHA1 and your package. Oauth Consent screen with your email and product name.

Make sure that you have the permission and all the packages needed, example below:

applicationId in tag <application> 
package name in AndroidManifest.xml 
package name in Credentials in Google Developer Console

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 

Also, you need to call onActivityResult. need this to cater all possible error codes when a client fails to connect to Google Play Services.

Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
  • Google+ Api is already enabled, in my Google Dev Console, there's only one record (OAuth2), the details (SHA1 fingerprint + Package) are correct, added the permission, and added the Plus Profile, still the same issue, check the updated code. – Jaeger Nov 17 '16 at 15:31
0

In my case I was trying to logout from google even though user have never logged in using google before for my app

const signInGoogle = async () => {
    try {
      await GoogleSignin.hasPlayServices();
      const userInfo = await GoogleSignin.signIn();
      console.log(userInfo);
      const payload = {
        token: userInfo.idToken,
        first_name: userInfo.user.givenName,
        last_name: userInfo.user.familyName,
        email: userInfo.user.email,
      };
      props.actions.socialLogin(payload);
      console.warn('google', payload);
    } catch (error) {
      if (error.code === statusCodes.SIGN_IN_CANCELLED) {
        // user cancelled the login flow
        alert('Cancel');
      } else if (error.code === statusCodes.IN_PROGRESS) {
        alert('Signin in progress');
        // operation (f.e. sign in) is in progress already
      } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
        alert('PLAY_SERVICES_NOT_AVAILABLE');
        // play services not available or outdated
      } else {
        console.log(error);
      }
    }
  }
  const handleGoogle = async () => {

    try{
      await GoogleSignin.revokeAccess();
      await GoogleSignin.signOut();
      signInGoogle()
    }catch(e){
      //HERE IT Throws the SIGN_IN_REQUIRED ERROR DUE TO signOut function
      signInGoogle()
    }
  };
Rahul Shakya
  • 1,269
  • 15
  • 15