我在android java中使用phonenumber做firebaseauth。
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// [START_EXCLUDE silent]
mVerificationInProgress = false;
// [END_EXCLUDE]
signInWithPhoneAuthCredential(credential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
// [START_EXCLUDE silent]
mVerificationInProgress = false;
// [END_EXCLUDE]
if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Invalid request
} else if (e instanceof FirebaseTooManyRequestsException) {
// [END_EXCLUDE]
}
}
@Override
public void onCodeSent(@NonNull String verificationId,
@NonNull PhoneAuthProvider.ForceResendingToken token) {
// Save verification ID and resending token so we can use them later
mVerificationId = verificationId;
mResendToken = token;
//and do the signinwithcredential here using PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
}
我愿意
// Firebase Authentication
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
if (mVerificationInProgress && validatePhoneNumber(phoneNumber)) {
startPhoneNumberVerification(phoneNumber);
}
}
但是问题是 有时,它说我何时使用短信代码登录!
Firebase Phone Authentication Error: The SMS Code Has Expired
我使用了相同的电话号码,有一天可以正常使用,而另一天则不能。 发生这种情况时,我会稍等片刻,然后重试,它可以正常工作。
我可以获得任何帮助吗?
谢谢!