简体   繁体   中英

PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) Getting this error While Sign in with Google Play

I want to Sign in with Google Play Services But Getting this error...I Tried Every solution possible Like Adding the SHA-1, Generating the Client ID, Publishing the Consent Screen,but it still gives this exception Here is my Code Snippet

Future<AuthCredential?> getGoogleCredential() async {
  print('Inside getGoogleCredential');
  final GoogleSignIn googleSignIn = GoogleSignIn(
    signInOption: SignInOption.games,
     scopes: [GamesApi.gamesScope],
     clientId: 'client id',
    hostedDomain: 'my hosted domain',
  );
  // print('google Sign in is ${googleSignIn.clientId}');
  print('google Sign in is ${googleSignIn.currentUser}');

  final GoogleSignInAccount? googleUser =
      await googleSignIn.signIn().catchError((error) {
    print('Failed to sign in with Google Play Games: $error');
  });

  print('google User is ${googleUser}');

  if (googleUser == null) {
    print('Failed to sign in with Google Play Games.');
    return null;
  }

  final GoogleSignInAuthentication googleAuth =
      await googleUser.authentication;
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );

  return credential;
}

Future signIn() async {
  final AuthCredential? googleCredential = await getGoogleCredential();
  if (googleCredential != null) {
    await FirebaseAuth.instance.signInWithCredential(googleCredential);
  } else {
    print('Trying signInAnonymously');
    await FirebaseAuth.instance.signInAnonymously();
  }
}

Basically the error is ApiException: 10 . To solve this, you will need register your app with a SHA1 on google cloud console.

Go to https://console.cloud.google.com/

click credentials > create credentials >OAuth client ID

choose the platform in which you want you application to work on.

fill in the package name of your application.

In order to fill in the SHA1 value, open your command line and cd to the android folder inside you main project folder and type the command ./gradlew signingReport then hit enter. After some computations have been done, you will see the SHA1 value in the format of an extended mac address.

Incase you get an error in the terminal, install the java jdk supported by your gradle version (as of the time of this answer, java jdk version 14 is supported) and set its path including the bin folder in windows environmental variable as a new path

This also can happens if you forget to add Google Play SHA1 Console to firebase app Settings

How to do:

  1. go to Google Play Console -> Your App -> App Integrity -> App SignIng --> App signing key certificate -> copy the SHA-1 and SHA-256

  2. go to firebase project settings and add above SHA-1 and SHA-256

ideally you should have 6 certificate in firebase settings.

3 SHA-1 --> ( dev / release / play console )

3 SHA-256 --> ( dev / release / play console )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM