5

I'm working on an app in Android studio that is using Google Play Games services for achievements and leaderboards, but I'm getting the error while trying to sign in. I followed the documentation, all my keys and OAuth codes are matching and still I am getting this error when I try to sign in:

com.google.android.gms.common.api.ApiException: 4: 4:

I looked everywhere for an answer, restarted all the credentials, unpublished and then published all new stuff needed, checked all the IDs. If anyone could give me some advice on what else to try ill be really grateful.

com.google.android.gms.common.api.ApiException: 4: 4: 
    at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
    at com.google.android.gms.common.internal.zai.zaf(Unknown Source)
    at com.google.android.gms.common.internal.zaj.onComplete(Unknown Source)
    at com.google.android.gms.common.api.internal.BasePendingResult.zaa(Unknown Source)
    at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source)
    at com.google.android.gms.auth.api.signin.internal.zzj.zzc(Unknown Source)
    at com.google.android.gms.auth.api.signin.internal.zzt.dispatchTransaction(Unknown Source)
    at com.google.android.gms.internal.auth-api.zzd.onTransact(Unknown Source)
    at android.os.Binder.execTransact(Binder.java:461)

This is the code used from Google docs for sign-in.

private void startSignInIntent() {
    GoogleSignInClient signInClient = GoogleSignIn.getClient(
        this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
    );
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result =
            Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // The signed in account is stored in the result.
            GoogleSignInAccount signedInAccount = result.getSignInAccount();
        } else {
            String message = result.getStatus().getStatusMessage();
            if (message == null || message.isEmpty()) {
                message = getString(R.string.signin_other_error);
            }
            new AlertDialog.Builder(this)
                .setMessage(message)
                .setNeutralButton(android.R.string.ok, null)
                .show();
        }
    }
}
hata
  • 11,633
  • 6
  • 46
  • 69
BigBoiVladica
  • 181
  • 1
  • 12

3 Answers3

4

When I had this problem, there were two things I had to do:

  1. Sign my app (usually with my release key) and deploy the app to my phone using adb

  2. Go to console.developers.google.com, to to the credentials section, go down to OAuth 2.0 client IDs, find my app, click it, and enter the SHA1 key from your release key.

Also, it's worth noting for anyone else who comes across this, you have to use what the OP is doing before you can do the silentSignIn. OP, you shouldn't have to worry about this.

EDIT: Never mind, it looks like it was the silentSignIn that was causing the OP problems.

SECOND EDIT: I think this answer is somewhat wrong. I think you can find the correct answer here: https://stackoverflow.com/a/56463302/5434860

retodaredevil
  • 1,261
  • 1
  • 13
  • 20
  • 1
    Hi, I tried your suggestions and so far no luck. Do you by any chance have another one? I'm still unable to sign in. This is driving me crazy. Thanks anyway – BigBoiVladica Apr 27 '19 at 15:19
  • Can I ask how long you waited? I remember it might have took an hour for it to start working after I got the correct SHA1 code in the right spot. Also, before I even got it working, when I signed in, the green google play rectangle popped up when I wanted to sign in, but I still got the error. If that's happening to you it means you are a little closer. – retodaredevil Apr 27 '19 at 15:22
  • I've waited for about 3 hours. When I try to sign in I'm getting the green pop up with animation, but when the animation ends I get error code above. Even though I tried all the things I mentioned above I'm still getting the same error. Also, I published apps before with Google Play Games services (which are working fine) and I never got this type of error. I dunno I'm going to try until I succeed. – BigBoiVladica Apr 27 '19 at 15:28
  • You aren't doing a signInClient.silientSignIn() anywhere by any chance? Also, in the onActivityResult, try logging to the console GoogleSignIn.getLastSignedInAccount(this) to see if that's null, if it isn't, you may be able to use it. Also in onActivityResult, I got the GoogleSignInAccount a little differently (It will probably produce same results, but may be worth a try): https://github.com/retrodaredevil/track-shooter/blob/45dfecc9b07cb60ad357b20a1d75ba2727ad756b/android/src/me/retrodaredevil/game/trackshooter/AndroidAchievementHandler.java#L124 (On line 124) – retodaredevil Apr 27 '19 at 15:34
  • I'm doing silentSignin in the onCreate method so when the user enters the app it is triggered if there is no one logged in. Thanks for the advice Ill try that now :D. – BigBoiVladica Apr 27 '19 at 15:38
  • Yeah, that's going to be my guess to why that's happening. You should only call silentSignIn after the user presses the sign in button and should only call it in the onResume. Let me know if that works. Yesterday this was a major headache for me as well. – retodaredevil Apr 27 '19 at 15:40
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/192531/discussion-between-supakalmb-and-retodaredevil). – BigBoiVladica Apr 28 '19 at 18:38
  • I'm glad you had some discussion by chat, but do you remember the solution by any chance, and will you share it to the community ? Thanks ! (I seem to be in the exact same case...) – Orabîg Oct 02 '19 at 21:06
  • @Orabîg this answer might help you. I don't remember what we talked about in chat exactly. https://stackoverflow.com/a/56463302/5434860 – retodaredevil Oct 04 '19 at 16:11
  • I have the same problem and sign the app with the release key solves my problem – chenxi Aug 15 '23 at 04:40
  • @chenxi signing with your release key will solve the problem because you have that key correctly setup with your linked app. However, the answer I linked in my answer says you should be able to add a second linked app to configure a separate key. When I played with this years ago I believe I added a linked app for my debug key that I found somewhere in Android Studio files. I recommend doing that as it means that you won't accidentally sign debug releases with your production release key. – retodaredevil Aug 16 '23 at 16:19
1

I added my app_id to the resource folder and and in my manifest I went @string/app_id,and now a got a SUCCESS from the Api, will test further to see if results are valid.

1

If you're using Play Games Services v2 SDK,

implementation 'com.google.android.gms:play-services-games-v2:17.0.0'

I got this error when I tried to sign-in with GoogleSignIn API and Play Games Services v2 SDK.

With v2 SDK, You can't sign-in or sign-out with GoogleSignIn API, any more. (cf. Remove sign-in and sign-out calls)

Sign-in is triggered automatically when your game is launched (for the first time), or you can trigger it manually with GamesSignInClient.signIn(). (cf. Migrate to Play Games Services Sign In v2)

So your code could be modified like:

private void startSignInIntent() {
    PlayGames.getGamesSignInClient(this).signIn();
}

(If you use signInSilently, you can refer my another answer for additional information.)

hata
  • 11,633
  • 6
  • 46
  • 69