googlesamples / google-services

A collection of quickstart samples demonstrating the Google APIs for Android and iOS
https://developers.google.com
Apache License 2.0
3.07k stars 2.53k forks source link

ApiException: 8 after app installation #381

Open Nynuzoud opened 6 years ago

Nynuzoud commented 6 years ago

Describe the problem:

ApiException: 8 after calling Task.getResult()

This error happens only first time you try login after app installation. Then, I'm clicking "Sign in button" to execute the code below. I'm choosing my google account and I'm catching ApiException: 8 that means "Internal Error" (https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes). So, I'm clicking "Sign in button" again and it works perfectly since that moment. I can logout and sign in as many times as I want and it will work.

If you clear data of the app, the error will not repeat. Also, it works without error on older devices with android 4.4.2, 5.1, 6, 7.1. Error appears also on emulator with Android version 9.

Steps to reproduce:

  1. Install app
  2. Click "Sign in with Google" button
  3. Catch ApiException: 8
  4. Click "Sign in with Google" button again.
  5. Signed in successfully

Relevant Code:

Task task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); // Signed in successfully, do something with account. ... } catch (ApiException e) { e.printStackTrace(); }

mhrpatel12 commented 5 years ago

any luck with this? I'm also facing the same issue. Double checked signing keys in firebase as well as google developer console, and it doesn't seem to be working.

Nynuzoud commented 5 years ago

No luck :( Still the same

Mikkelet commented 5 years ago

Getting the same!

lnavarrogeodb commented 4 years ago

Me too!

fractalbob commented 4 years ago

Oh, great: This bug has been open over a year and a half and Google STILL hasn't replied to any of the developers reporting it!

Nikoloutsos commented 4 years ago

@fractalbob The only workaround that I found was to click sign in button programatically if an exception like this happens!

fractalbob commented 4 years ago

Or execute recursively in the method that calls the operation, which is what I ended up doing:

private void processGmailSignIn(Intent data) {
    Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
    try {
        // Google Sign In was successful, authenticate with Firebase
        GoogleSignInAccount account = task.getResult(ApiException.class);
        firebaseAuthWithGoogle(account);
    } catch (ApiException e) {
        if (e.getStatusCode() == INTERNAL_ERROR) {
            processGmailSignIn(data);
            return;
        }
    }    
}
efraespada commented 4 years ago

I just realized this exception only happens when I try to do login when I've previously made a login in another device in the same app/project with the same Google account.

Logout the app on the other device to solve the problem.

gopalanrc-nam commented 3 years ago

Or execute recursively in the method that calls the operation, which is what I ended up doing:

private void processGmailSignIn(Intent data) {
    Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
    try {
        // Google Sign In was successful, authenticate with Firebase
        GoogleSignInAccount account = task.getResult(ApiException.class);
        firebaseAuthWithGoogle(account);
    } catch (ApiException e) {
        if (e.getStatusCode() == INTERNAL_ERROR) {
            processGmailSignIn(data);
            return;
        }
    }    
}

Above solution not working

Nynuzoud commented 3 years ago

I just realized this exception only happens when I try to do login when I've previously made a login in another device in the same app/project with the same Google account.

Logout the app on the other device to solve the problem.

It's been a 2 years already, I don't remember was I logged in from another device or not but anyway there're two questions:

  1. Let's assume I was logged in from another device but why this error happens every time I reinstall the app on device that I try to log in.
  2. Shouldn't be there another error with meaningful message instead of just Internal Error?
LeoPersike commented 2 years ago

Any luck with this? I am facing the same issue, but I get the message 100% of the attempts, even clicking multiple times on the sign in button...

Support would be appreciated. +1 on "Internal error" doesn't help.

fractalbob commented 2 years ago

Are you getting the error on Google sign-in or passwordless email sign-in?

On Fri, Sep 23, 2022, 13:05 Persike @.***> wrote:

Any luck with this? I am facing the same issue, but I get the message 100% of the attempts, even clicking multiple times on the sign in button...

Support would be appreciated. +1 on "Internal error" doesn't help.

— Reply to this email directly, view it on GitHub https://github.com/googlesamples/google-services/issues/381#issuecomment-1256075692, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALTQDOL5NKG7OJAOU2OFK3V7WFH5ANCNFSM4FTR4LAQ . You are receiving this because you were mentioned.Message ID: @.***>

cieplakm commented 1 year ago

This problem occurs when:

  1. Succesfully signed in,
  2. Go to Google profile (Apps Access) and remove access for app,
  3. Try to sign-in - should be successfully signed in,
  4. Use service - i.e GDrive -> should be UserRecoverableAuthException
  5. Use intent form UserRecoverableAuthException.getIntent() to startActiviyForResult a. Give consent without Drive Access
  6. In onActivityResult on GoogleSignIn.getSignedInAccountFromIntent(data).getResult(ApiException.class) ->ApiException, with code 8. only if allow processing with requestCode != -1
falk-stefan commented 1 year ago

Facing the same issue. I've added the google-service.json to my Android project, I'm logged in on the Emulator Device, I've checked all IDs and keys and also added the SHA-1 and SHA-256 to my Firebase project yet I keep getting the exception in getSignedInAccountFromIntent() after running:

private fun signIn() {

    val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(getString(R.string.default_web_client_id))
        .requestEmail()
        .build()
    val googleSignInClient = GoogleSignIn.getClient(this, gso)
    val signInIntent = googleSignInClient.signInIntent

    val task = GoogleSignIn.getSignedInAccountFromIntent(signInIntent)

    try {
        val auth = Firebase.auth
        // Authenticate with Firebase using Google credentials
        val account = task.getResult(ApiException::class.java)
        val credential = GoogleAuthProvider.getCredential(account?.idToken, null)
        auth.signInWithCredential(credential)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    // User is logged in, obtain JWT token and return to calling activity
                    val user = auth.currentUser
                    user?.getIdToken(true)?.addOnSuccessListener { result ->
                        val token = result.token
                        val resultIntent = Intent()
                        Timber.i(String.format("Logged in; Token %s", token))
                        resultIntent.putExtra("jwt_token", token)
                        setResult(Activity.RESULT_OK, resultIntent)
                        finish()
                    }
                } else {
                    // Authentication failed, show error message
                    Toast.makeText(this, "Authentication failed.", Toast.LENGTH_SHORT).show()
                }
            }
    } catch (e: ApiException) {
        Timber.e(e);
        // Google Sign-In failed, show error message
        Toast.makeText(this, "Google sign-in failed.", Toast.LENGTH_SHORT).show()
    }
}