java - 获取 Firebase 电话身份验证 OTP 时出错
问题描述
我正在尝试实施 Firebase 电话验证。我已在 Firebase 控制台上启用电话验证。我已生成密钥库并将 SHA 签名添加到控制台。
依赖项:
dependencies {
def multidex_version = "2.0.1"
implementation platform('com.google.firebase:firebase-bom:26.0.0')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics'
implementation "androidx.multidex:multidex:$multidex_version"
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
}
phone_verification.dart
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: '+1234567890',
verificationCompleted: (PhoneAuthCredential credential) {
print('verificationCompleted');
},
verificationFailed: (FirebaseAuthException e) {
print('verificationFailed');
if (e.code == 'invalid-phone-number') {
print('The provided phone number is not valid.');
}
else {
print('Some error occoured: $e');
}
},
codeSent: (String verificationId, int resendToken) async {
print('codeSent');
// Update the UI - wait for the user to enter the SMS code
String smsCode = '123456';
// Create a PhoneAuthCredential with the code
PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);
},
timeout: const Duration(seconds: 60),
codeAutoRetrievalTimeout: (String verificationId) {
print("Timeout: $verificationId");
},
);
执行上述块时,收到以下错误。控制台输出:
E/FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with {
"error": {
"code": 400,
"message": "INVALID_CERT_HASH",
"errors": [
{
"message": "INVALID_CERT_HASH",
"domain": "global",
"reason": "invalid"
}
]
}
}
400
V/FA: Recording user engagement, ms: 1165
E/zza: Failed to get reCAPTCHA token - calling backend without app verification
解决方案
@CubeRootX 和 @user13864571
您的问题与 SHA1 和 SHA256 密钥有关。您必须添加它们以验证您的证书。
去
- 您项目的 Firebase 控制台
- 验证
- 项目设置(从项目概述附近的设置按钮)
- 添加指纹
- 添加密钥库的 SHA-1 和 SHA-256 值。
您可以像这样从 gradle 获取密钥库。
./gradlew 签名报告
阅读此内容以获取更多信息:https ://firebase.google.com/docs/auth/android/phone-auth#enable-app-verification
推荐阅读
- tensorflow - 有没有办法找到 tf.data.Dataset 的批量大小
- php - 准备好的语句登录需要获取原始
- alexa - 亚马逊 Alexa 编程语言
- jenkins - 收到错误 Jenkins 管道泊坞窗:找不到命令
- raspberry-pi - 使用 PN532 和 Raspberry Pi 检测徽章的问题
- ruby-on-rails - 使用地理位置查找附近的事件
- c# - 如何在快速彩色文本框中设置字符串样式
- ios - Flutter 为 BlinkId 插件添加新的 ViewController
- python - 如何在 GCP 中托管 Python 包并从 Compute Engine 访问它们?
- javascript - 对象键过滤