2

I developed a game in android. I tried to implement the GooglePlay SignIn but it shows an error. I'm not able to debug this error. I tried installing the app in different phone models other than emulators.

Code:

public void startSignInIntent() {     
    startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {

        if (requestCode == RC_SIGN_IN) {

            Task<GoogleSignInAccount> task =
                    GoogleSignIn.getSignedInAccountFromIntent(intent);

            try {
                GoogleSignInAccount account = task.getResult(ApiException.class);
            } catch (ApiException apiException) {
                String message = apiException.getMessage();
                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();
            }

        }
        super.onActivityResult(requestCode, resultCode, intent);
    }

It Loads the GP Games

Then this happens

EDIT

Now after following the suggested methods, the SignIn dialogue closes immediately without showing any errors.

PSN
  • 2,326
  • 3
  • 27
  • 52
  • I thenk the issue is task is executed asynchronously, it simply does not have result when you call 'getResult', what you want here is probably smth like 'awaitResult'. – IcedLance Apr 10 '19 at 11:26
  • @IcedLance Could you post a code for that? – PSN Apr 10 '19 at 11:27
  • Sry, on my phone but you can see it here: https://developers.google.com/android/guides/tasks#blocking – IcedLance Apr 10 '19 at 11:29
  • I tried this but same problem. – PSN Apr 10 '19 at 11:55
  • Sorry, was wrong, your code is correct. But there're a couple other questionsbon StackOverflow about a very similar issue, maybe take a look at one of them like this one: https://stackoverflow.com/questions/28919040/android-connecting-to-google-play-still-gives-error-code-4/28991289#28991289 – IcedLance Apr 10 '19 at 14:29
  • Try to change your code to this: `GoogleSignInResult task = Auth.GoogleSignInApi.getSignInResultFromIntent(intent);`. Check this [documentation](https://developers.google.com/games/services/android/signin#performing_interactive_sign-in) for more details. – Jessica Rodriguez Apr 10 '19 at 15:44
  • @IcedLance Yea, I saw that too. I configured everything correctly. – PSN Apr 10 '19 at 16:09
  • @jess I changed according to the documentation. Now I get "There was an issue with Signin. Please try again later" – PSN Apr 10 '19 at 16:11

1 Answers1

2

The message of the ApiException is not really telling:

String message = apiException.getMessage();

To debug this, the status of the ApiException would rather be helpful:

int StatusCode = apiException.getStatusCode();

See the documentation; It could have to do with oAuth2 scopes; but the question lacks the code where the GoogleSignInClient is being constructed (might be relevant to reproduce the error).

Another suspicion would be a missing or outdated google-services.json. It needs to have the matching (debug or release or both) key fingerprints added, of the keys used to sign that APK package. Even if not using Firebase, one has to setup the project there, in order to add the key fingerprints and to obtain that one config file (there has to be some google_app_id in the string resources and this is exactly what the Play Services Plugin would generate from that config file).


Status 4 means SIGN_IN_REQUIRED:

The client attempted to connect to the service but the user is not signed in.

The client may choose to continue without using the API.

A failed authentication hints for google_app_id or the key fingerprints not matching. Think one does not require permission to get the currently signed-in Google account with the GoogleSignInClient... so this likely means, the API client not being signed in to Google Play.

Community
  • 1
  • 1
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Same error: code 4. I have already pasted debug and release keys to play console while linking. – PSN Apr 27 '19 at 23:35
  • Is there any way to delete the game from the games console and start from scratch? – PSN Apr 28 '19 at 00:06
  • @PSN you don't have to delete it from there, but instead have to link the accounts in between Firebase and the Play Console, plus the matching keys. Not up for a chat since it's 2am here and programmed all day. – Martin Zeitler Apr 28 '19 at 00:14
  • I have setup Firebase and Play Console properly I guess. I gave both keys. Well, for release key I gave the google SHA1 since I opted for Gplay signing. – PSN Apr 28 '19 at 00:20
  • @PSN with Play signing one has to add up to 3 fingerprints; but adding the fingerprints API side does not help unless having the correct `google_app_id` in the sting resources (one can add it manually, too - but one can only get it from the `google-services.json`... at least have no clue where else to get it). – Martin Zeitler Apr 28 '19 at 00:24
  • Google App ID is present in the Play Games Console right? – PSN Apr 28 '19 at 00:25
  • @PSN There is no `google_app_id` and there is no way to add debug key fingerprints in the Play Console ...the package name does not matter, the `google_app_id` looks whole different. – Martin Zeitler Apr 28 '19 at 00:29
  • How to obtain the app_id? – PSN Apr 28 '19 at 00:31
  • this is how the output of the plugin looks alike: [processing the json file](https://developers.google.com/android/guides/google-services-plugin#processing_the_json_file). – Martin Zeitler Apr 28 '19 at 01:21
  • 1
    I tried this https://console.developers.google.com/apis/credentials Credentials -> OAuth consent screen -> Scopes for Google APIs, and now it is closing. No errors are shown. – PSN Apr 28 '19 at 06:41
  • It's not an error. I finally logged in. Thank you for the detailed answer. – PSN Apr 28 '19 at 08:08