Alipop
Alipop

Reputation: 33

Flutter Error:(getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@3e2567)

Hello when I make Auth phone with Firebase in my reel device I Can't do this do this always returns this Error

(getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@3e2567)

And

This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console. [ App validation failed ]

but this Error just showing when auth phone but when using email/password i'ts working good.. How can I solved this problem and make auth with phone

this my function

String phonenumber;
String smsCode;
String vialdid;

Future<void> verfityphoen()async{

  final PhoneCodeAutoRetrievalTimeout AutoRetriv =(String verid) {
    this.vialdid =verid;
  };


  final PhoneCodeSent smsCodeset =(String verid,[int forceResendingToken]){
this.vialdid=verid;
smscodeDialog();

  };
final PhoneVerificationCompleted verfiedcompletd=(AuthCredential user){
  print('verfild');
};
  final PhoneVerificationFailed verfilederror =(AuthException exception){
    print('${exception.message}');
  };


  await FirebaseAuth.instance.verifyPhoneNumber(
      phoneNumber:"+967733659520",
      timeout: const Duration(seconds: 5),
      verificationCompleted: verfiedcompletd,
      verificationFailed: verfilederror,
      codeSent: smsCodeset,
      codeAutoRetrievalTimeout: AutoRetriv
  );



}

Future<bool> smscodeDialog(){
  return showDialog(
      context:context,barrierDismissible: false,
      builder:(context){
    return AlertDialog(
      title: Text('enter codesms'),
      content: TextField(
        onChanged: (val){
          this.smsCode=val;
        },


      ),
      actions: <Widget>[
        new FlatButton(
            onPressed: (){

              FirebaseAuth.instance.currentUser().then((user){
                if (user!=null){
                 Navigator.pop(context);
                 Navigator.push(context, MaterialPageRoute(builder:(context)=>Home()));
                }else{

                  Navigator.pop(context);
                  _testSignInWithPhoneNumber();
                }


              });

            },
            child:Text('Clike '))

      ],
    );
        });
}

 _testSignInWithPhoneNumber() async {
  String _smsCodeController;
  final AuthCredential credential = PhoneAuthProvider.getCredential(
    verificationId: vialdid,
    smsCode: smsCode,
  );
  final FirebaseUser user = (await _auth.signInWithCredential(credential)) as FirebaseUser;
  final FirebaseUser currentUser = await _auth.currentUser();
  assert(user.uid == currentUser.uid);

  _smsCodeController = '';
  return 'signInWithPhoneNumber succeeded: $user';
}

pubspec.yaml

cloud_firestore: ^0.13.5
  firebase_auth: ^0.16.0
  firebase_core: ^0.4.0+9
  provider: ^4.0.5

gradle

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.3.3'
    }

Upvotes: 0

Views: 1856

Answers (1)

EPetit
EPetit

Reputation: 50

(I'm French, I have probably made some errors in my answer..)

I had the same problem few weeks ago. I forgot to put SHA1 key in Firebase. Looking at your error message, I guess it's the same problem ! Are you sure to have save correct SHA-1 key in Firebase ? To do so, I had to install the latest java jdk and with the terminal in Android Studio, I went to the folder jdk -> bin and execute the function : keytool -list -v -alias androiddebugkey -keystore {C:\\ … path to android folder }\.android\debug.keystore. You can find a lot of video on YouTube about this.

In the terminal, I received a SHA-1 key ! I just had to go on Firebase -> settings of my project and at the bottom of the page, I added my key.

I hope it could help you !

Upvotes: 2

Related Questions