【发布时间】:2021-12-30 05:05:56
【问题描述】:
我正在开发一个 Flutter 移动应用并在 Android 模拟器上进行测试。
我正在使用 Firebase 来处理身份验证逻辑。
我创建了一个服务
class AuthService {
Future<void> googleLogin() async {
try {
final googleUser = await GoogleSignIn().signIn();
if (googleUser == null) return;
final googleAuth = await googleUser.authentication;
final authCredential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken
);
await FirebaseAuth.instance.signInWithCredential(authCredential);
} on FirebaseAuthException catch (e) {
// handle the error
}
}
}
我按下一个按钮就可以调用它。但是,我确实使用我的 Google 帐户进行身份验证,然后终端显示此错误
PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 12500: , null, null)
我在网上看到这是由于我的 firebase 项目中缺少 SHA 凭据。所以我使用项目中android 目录中的./gradlew signingReport 生成了这些凭据。然后我将证书(SHA-1 和 SHA-256 添加到我的颤振项目中的 android 应用程序中。
我再次下载了 Firebase 提供的 Google 服务文件,运行 flutter clean 和 flutter run,但尝试登录时仍然遇到同样的问题。
为什么会这样?我错过了什么吗?
【问题讨论】:
标签: android firebase flutter firebase-authentication google-signin