没有verificationProof,sessionInfo,临时证明或注册ID,无法创建PhoneAuthCredential [英] Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID

查看:37
本文介绍了没有verificationProof,sessionInfo,临时证明或注册ID,无法创建PhoneAuthCredential的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 firebase 电话身份验证,在我的电话号码上收到代码后,代码会跳转到 verifysignincode()方法,但无法创建 phoneAuthCredentials.程序捕获的异常是如果没有 verificationProof sessionInfo ,临时证明或注册ID,就无法创建 PhoneAuthCredential ."

I'm working on firebase phone authentication, after receiving code on my phone number the code jumps to verifysignincode() method, it fails to create phoneAuthCredentials. The exception which program catches is "Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID."

这是我的发送代码方法:

This is my send code method:

    public void send_code(){
    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
            super.onCodeSent(s, forceResendingToken);
            Log.d("code", "onCodeSent:" + s);
            verificationID=s;
        }
        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {

        }
        @Override
        public void onVerificationFailed(@NonNull FirebaseException e) {
            Toast.makeText(PhoneAuthentication.this, e.getMessage(), Toast.LENGTH_SHORT);
        }
    };
    mPhoneAuthProvider.verifyPhoneNumber(
            user_contact , 60, TimeUnit.SECONDS, PhoneAuthentication.this, mCallbacks
    );}

这是我的验证登录方法:

This is my verify sign in method:

    public void verifySignInCode(String code){
    try {
        PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationID, code);
        signInWithPhoneAuthCredential(credential);
    }catch (Exception e){
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();

    }
}

这是我的带有电话凭据的登录方法:

this is my signin method with phone credentials:

    private  void signInWithPhoneAuthCredential(PhoneAuthCredential credential){
    mFirebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if(task.isSuccessful()){

                        startActivity(new Intent(PhoneAuthentication.this, UserHome.class));
                    }
                    else {
                        Log.d("error:", task.getException().getMessage());

                    }
                }
            });
}

错误:

没有任何verifyProof不能创建PhoneAuthCredential,sessionInfo,临时证明或注册ID.

Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID.

推荐答案

问题:这已经烧了我很长时间,经过研究,我知道这种情况是由于手机内存不足或网络连接不足所致.当您维护带有验证ID的日志时,即log.d(TAG,VerificationId),它将在VerificationId中显示为null,并且根据错误消息,它说如果没有验证证明,并且无法创建PhoneAuthCredential,并且verifyId是我们的验证证明.

Problem: This has burned me quite a long and after researching I got to know that this happens due to either low memory on phone or low network connection. When you maintain log with verification id i.e. log.d(TAG, verificationId) it will show null in verificationId and as per the error it says cannot create PhoneAuthCredential without verification proof and verificationId is our verification proof.

解决方案:

  1. 清除电话缓存,然后再次尝试签名.转到应用信息并清除缓存.
  2. 还原实例状态

private String verificationId;
private static final String KEY_VERIFICATION_ID = "key_verification_id";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_otp);

    // Restore instance state
    // put this code after starting phone number verification
    if (verificationId == null && savedInstanceState != null) {
        onRestoreInstanceState(savedInstanceState);
    }
}//end of onCreate

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString(KEY_VERIFICATION_ID,verificationId);
}

@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    verificationId = savedInstanceState.getString(KEY_VERIFICATION_ID);
}

发生的情况是verificationId存储在本地,有时由于内存不足而丢失.因此,为了解决这种情况,我们必须还原实例状态,该状态不会让VerificationId丢失.

What happens is the verificationId is stored locally and it is lost sometimes due to less memory. So to tackle this situation we have to restore Instance State which won't let the verificationId to be lost.

这篇关于没有verificationProof,sessionInfo,临时证明或注册ID,无法创建PhoneAuthCredential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆