【问题标题】:Google sign_in_failed error in a Flutter app using firebase auth使用 Firebase 身份验证的 Flutter 应用程序中的 Google sign_in_failed 错误
【发布时间】: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-1SHA-256 添加到我的颤振项目中的 android 应用程序中。

我再次下载了 Firebase 提供的 Google 服务文件,运行 flutter cleanflutter run,但尝试登录时仍然遇到同样的问题。

为什么会这样?我错过了什么吗?

【问题讨论】:

    标签: android firebase flutter firebase-authentication google-signin


    【解决方案1】:

    您必须像这样在 Firebase 控制台中添加支持电子邮件 ID

    【讨论】:

    • 谢谢,成功了!
    • 很高兴为您提供帮助:)
    猜你喜欢
    • 2019-12-20
    • 2017-04-23
    • 2023-02-04
    • 2022-01-11
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    相关资源
    最近更新 更多