3

am using google play services silent login, but it always CompleteListener show com.google.android.gms.common.api.ApiException: 4: 'SIGN_IN_REQUIRED' but am a test user in my application. My code is below,

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());
}

@Override
   protected void onResume() {
       super.onResume();
       signInSilently();
}

private void signInSilently() {

    mGoogleSignInClient.silentSignIn().addOnCompleteListener(this, new OnCompleteListener<GoogleSignInAccount>() {
    @Override
       public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
           if (task.isSuccessful()) {
              try {
                   GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
              } catch (ApiException apiException) {
                   System.out.println("CATE_RESULT_CODE " + apiException.getLocalizedMessage()+" " +apiException.getStatusMessage()+ " " +apiException.getMessage()+ " "+apiException.getCause() );
              }
           } else {
                try {
                    GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
                } catch (ApiException apiException) {
                      System.out.println("CATE_RESULT_CODE " + apiException.getLocalizedMessage()+" " +apiException.getStatusMessage()+ " " +apiException.getMessage()+ " "+apiException.getCause() );
                }
           }
        }
     });
  }

My gradle file dependencies :

dependencies {
 ext {
    support_library_version = '27.0.2'
    google_play_services_version = '15.0.2'
  }
    implementation "com.android.support:appcompat-v7:${support_library_version}"
    implementation "com.android.support:design:${support_library_version}"
     implementation "com.android.support:recyclerview-v7:${support_library_version}"
     implementation "com.android.support:cardview-v7:${support_library_version}"
     implementation 'com.google.android.gms:play-services-auth:15.0.1'
     implementation 'com.google.android.gms:play-services-games:15.0.1'
 }

 erorr :
  com.google.android.gms.common.api.ApiException: 4: 
    at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
    at com.google.android.gms.common.internal.zzk.convert(Unknown Source)
    at com.google.android.gms.common.internal.zzl.onComplete(Unknown Source)
    at com.google.android.gms.common.api.internal.BasePendingResult.zza(Unknown Source)
    at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source)
    at com.google.android.gms.auth.api.signin.internal.zzk.zzd(Unknown Source)
    at com.google.android.gms.auth.api.signin.internal.zzu.dispatchTransaction(Unknown Source)
    at com.google.android.gms.internal.auth.zze.onTransact(Unknown Source)
    at android.os.Binder.execTransact(Binder.java:404)
    at dalvik.system.NativeStart.run(Native Method)

also adding app id in Manifest file.

Please give me a solution for this problem. Advance thanks

Mathan Chinna
  • 373
  • 3
  • 19

3 Answers3

1

error will be solved...

Anyone having this type of problem please check first your SHA 1 key from your Firebase project settings.

My SHA 1 key is mismatched from Firebase project settings.

Now am change that and work perfectly..

Thank you..

Mathan Chinna
  • 373
  • 3
  • 19
  • 1
    Please can you write exactly what you did to fix this error, where to get sha1 key and where to copy it – Kiryl Tkach Jul 05 '18 at 20:01
  • get SHA1 in your android studio, then go to your project from firebase settings-->Add Fingerprint place your SHA1 key. – Mathan Chinna Jul 18 '18 at 05:55
  • Does your app have to be a firebase app? I've been trying to do this all day while my app has nothing to do with firebase. If I just add firebase to my project will it start working? – retodaredevil Apr 24 '19 at 23:42
  • So I was actually able to login without my app having anything to do with firebase. I had the incorrect SHA1 key in console.developers.google.com. Once I put my SHA1 key from my jks in the correct spot there, since it was connected to my Game Service on Google play. Thanks for responding. I'll try integrating with firebase if I run into more problems. – retodaredevil Apr 25 '19 at 16:39
  • @MathanChinna i don't have firebase project for my application, then how to solve this problem bro? – MSARKrish May 05 '20 at 14:52
  • Nothing in your question suggest that you use firebase. Not just no tag for the question but I dont' even see any firebase dependency in your build.gradle snippet. – Csaba Toth Aug 22 '20 at 05:07
  • I'm facing same issue although SHA-1 is same. – Usman Rana May 21 '21 at 05:33
1

Follow this steps until you get the SHA-1 in Android Studio

https://stackoverflow.com/a/33479550/7772358

Then go to this link

https://console.firebase.google.com/

  1. Click setting gear Icon near the Project Overview under Firebase Logo on the left top
  2. Click on the Project setting and make sure you choose the right Project in the dropdown list In the General tab.
  3. Scroll down and find the SHA certificate fingerprints
  4. Click Add Fingerprint Copy and paste the SHA-1 from the Android studio console to the Certificate fingerprint column then click Save
  5. Restart the App that require firebase and google login.

Viola.

nandur93
  • 105
  • 8
0

it turns out whenver you add/edit your Firebase app settings (SHA certificate fingerprints) it generate the correlate credentials in your application Google Api console. Although the fingerprint was the same it didnt work until i deleted the cradential from Google Api and let Firebase generate it for me - i guess its ID related.

gor
  • 987
  • 1
  • 12
  • 25