首页 > 解决方案 > Google SignIn with firebase in flutter Exception PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

问题描述

我正在尝试使用 Firebase 的 googleSignIn。我的应用程序已经与 Firebase firestore 连接,并且可以完美地进行读/写(Crud)操作。现在我想集成 GoogleSignIn 。但是我遇到了一个未处理的异常。我尝试了一个这个平台答案和 Github 的大量解决方案,但不幸的是,它们都不能解决我的问题。

E/flutter ( 2995): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: ,null)

在此处输入图像描述

      final GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
      final GoogleSignInAuthentication googleSignInAuthentication =
     await googleSignInAccount.authentication;

final AuthCredential credential = GoogleAuthProvider.getCredential(
  accessToken: googleSignInAuthentication.accessToken,
  idToken: googleSignInAuthentication.idToken,
);

final AuthResult authResult = await _firebaseAuth.signInWithCredential(credential);
final FirebaseUser user = authResult.user;

assert(user.email != null);
assert(user.displayName != null);
assert(user.photoUrl != null);

name = user.displayName;
email = user.email;
imageUrl = user.photoUrl;

assert(!user.isAnonymous);
assert(await user.getIdToken() != null);

final FirebaseUser currentUser = await _firebaseAuth.currentUser();

assert(user.uid == currentUser.uid);

标签: fluttergoogle-cloud-firestorefirebase-authenticationgoogle-signinunhandled-exception

解决方案


如果您还没有这样做,请尝试将SHA1添加到 Firebase 项目。

这是代码 10 异常。出现“sign_in_failed”错误。您可以在此处获得一份报告,其中包含有关设置 SHA1 的相同说明。


推荐阅读