![](/img/trans.png)
[英]Firebase Phone authentication only sending OTP For Testing Phone Numbers
[英]Firebase is not sending OTP to the Mobile Number
我面臨着不同類型的問題。 我在我的應用程序中使用 Firebase 手機號碼身份驗證。 當我嘗試將 OTP 發送到我正在使用的同一手機號碼時,OTP 沒有發送。 但是,如果我從我的移動 OTP 發送 OTP 到其他手機。 我還發現如果我從另一部手機發送 OTP 到我的號碼,OTP 即將到來。 因此不存在手機號碼的問題。 在調試時我發現這個代碼塊不工作
@Override
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(verificationId, forceResendingToken);
Log.e(TAG, "onCodeSent: s - " + verificationId + " : t - " + forceResendingToken);
xVerificationId = verificationId;
}
對於其他號碼,它正在工作並且正在生成驗證和 forceResendingToken。
如果您在 firebase 下的測試中添加了您的電話號碼(登錄方法->電話)。 然后請從那里刪除以獲取 otp。
您是否正在實施onVerificationCompleted
? 在以下 2 種情況下,不會發送 OTP,如https://firebase.google.com/docs/auth/android/phone-auth 中所述:
在這種情況下,您將直接取回 PhoneAuthCredential。
如前所述,電話號碼正在通過以下方式自動驗證
這就是onCodeSent()
不起作用的原因。
現在,為了擺脫這個問題,您需要實現onVerificationCompleted()
,大多數情況下您已經實現了它,但您不知道里面放了什么。
如果您在 onVerificationCompleted() 中,那么您可能沒有 OTP,但您肯定有phoneAuthCredential
,您只需將此變量傳遞給mAuth.signInWithCredential()
,這應該會導致您獲得所需的輸出。
示例代碼:
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(getApplicationContext(),"Verifying code Automatically",LENGTH_LONG).show();
signInWithCredential(phoneAuthCredential);
}
示例代碼:
private void signInWithCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
// Log.d(TAG, "signInWithCredential:success");
} else {
// Sign in failed, display a message and update the UI
// Log.w(TAG, "signInWithCredential:failure", task.getException());
}
}
}
});
}
更新 SHA1 指紋。 它對我有用。
為我工作。
有時 Google 無法驗證來自您的應用的請求。 為了解決它。 重新生成您應用的簽名報告並獲取您的 SHA-1 或 SHA-256 指紋。 轉到您的 firebase 項目設置並添加這些指紋。
對我來說,應用程序 id 沒有更新,因為我更改了我的包名稱並生成了一個新的 google-services.json。
更新“applicationid”解決了這個問題!
在build.gradle
文件中使用依賴項實現“ androidx.browser:browser:1.2.0
”。 Firebase 現在想通過圖像檢查驗證,此依賴項將允許打開瀏覽器並驗證 Captcha,您將獲得 OTP。
就我而言,我意識到這個問題發生在所有從一個提供商轉移到另一個提供商的號碼上。 使用從未移植 Firebase 身份驗證的電話號碼就像一個魅力!
對於仍在尋找從 Khurshed 推薦的 Google Play Console 獲取 SHA 的文檔的任何人: Doc
就我而言,收到的 OTP 在垃圾郵件中。
欲了解更多信息, 請訪問
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.