Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleSignInResult isSuccess failed

I want to use the Google Login for my App, but I always get the message Status{statusCode=unknown status code: 12500, resolution=null and the login failed. Has anyone an idea what the problem is?

Here is my Activity:

public class GruppenActivity extends AppCompatActivity implements
    GoogleApiClient.OnConnectionFailedListener,
    View.OnClickListener {

    private static final String TAG = "SignInActivity";
    private static final int RC_SIGN_IN = 9001;

    private GoogleApiClient mGoogleApiClient;
    private TextView mStatusTextView;
    private ProgressDialog mProgressDialog;

    private LernAppDB db;
    private SQLiteDatabase sqlDatabase;

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

        // Views
        mStatusTextView = (TextView) findViewById(R.id.status);

        // Button listeners
        findViewById(R.id.sign_in_button).setOnClickListener(this);
        findViewById(R.id.sign_out_button).setOnClickListener(this);
        findViewById(R.id.disconnect_button).setOnClickListener(this);

        db = new LernAppDB(this);
        sqlDatabase = db.getReadableDatabase();


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

        mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this , this )
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

        SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
        signInButton.setSize(SignInButton.SIZE_STANDARD);
        signInButton.setScopes(gso.getScopeArray());

    }

    @Override
    public void onStart() {
        super.onStart();

        OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
        if (opr.isDone()) {
            Log.d(TAG, "Got cached sign-in");
            GoogleSignInResult result = opr.get();
            handleSignInResult(result);
        } else {

            showProgressDialog();
            opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
                @Override
                public void onResult(GoogleSignInResult googleSignInResult) {
                    hideProgressDialog();
                    handleSignInResult(googleSignInResult);
                }
            });
        }
    }

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

        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        }
    }

    private void handleSignInResult(GoogleSignInResult result) {
        Log.d(TAG, "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();
            String personName = acct.getDisplayName();
            String personEmail = acct.getEmail();
            ZentraleDB zentraleDB = new ZentraleDB();
            ZentraleDB.benutzerAnlegen(sqlDatabase,personEmail,"hans","wilhelm",personName,"tesr");
            mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
            updateUI(true);
        } else {
            updateUI(false);
        }
    }

    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }

    private void signOut() {
        Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    // [START_EXCLUDE]
                    updateUI(false);
                    // [END_EXCLUDE]
                }
            });
    }

    private void revokeAccess() {
        Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    updateUI(false);
                }
            });
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.d(TAG, "onConnectionFailed:" + connectionResult);
    }

    private void showProgressDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage(getString(R.string.loading));
            mProgressDialog.setIndeterminate(true);
        }

        mProgressDialog.show();
    }

    private void hideProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.hide();
        }
    }

    private void updateUI(boolean signedIn) {
        if (signedIn) {
            findViewById(R.id.sign_in_button).setVisibility(View.GONE);
            findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
        } else {
            mStatusTextView.setText(R.string.signed_out);

            findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
            findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sign_in_button:
                signIn();
                break;
            case R.id.sign_out_button:
                signOut();
                break;
            case R.id.disconnect_button:
                revokeAccess();
                break;
        }
    }
}
like image 731
Marius Beu Avatar asked Mar 21 '16 20:03

Marius Beu


4 Answers

Few things to check:

1. Check your correct SHA certificate fingerprints in Firebase Console.

2. Check below warning in Google API Console.

enter image description here

  • If you see that error, You need to choose Support email in OAuth consent screen tab like an example below.

enter image description here

After chosen a support email, the warning disappeared. and it started working.

like image 80
Rumit Patel Avatar answered Nov 20 '22 16:11

Rumit Patel


We had same problem Error 12500, nothing help... Code was ok, SHA-1 keys ok, checked a lot of times... Spend two days with this f**king issue...

But we didn't have accepted OAuth consent on page https://console.developers.google.com/apis/credentials/consent?project=[PROJECT_ID] That help, just accept and fill page with OAuth consent, and it start working without any issue after.

like image 41
mtrakal Avatar answered Nov 20 '22 18:11

mtrakal


I was using Google plus login successfully but faced same problem after changing the laptop I used for developing the app earlier.
Reason was change in SHA-1 registered on Google Developer Console.

So I'd recommend re-iterating the integration guide and fixing google-services.json (Configuration file) located in your app folder. Because problem could be with your in API keys, APIs enabled or the SHA-1.

like image 34
Ruturaj Patil Avatar answered Nov 20 '22 17:11

Ruturaj Patil


Calling the connect() function after the "sing-in" code worked for me.

     Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(sActivity.mGoogleApiClient);
    sActivity.startActivityForResult(signInIntent, RC_SIGN_IN);

    mGoogleApiClient.connect(); //Adding this worked for me!
like image 2
huse Avatar answered Nov 20 '22 17:11

huse