Flutter Firebase Auth/Google_sign_in无法使用statuscode = CANCELED登录 [英] Flutter Firebase Auth / Google_sign_in fail to login with statuscode=CANCELED

查看:200
本文介绍了Flutter Firebase Auth/Google_sign_in无法使用statuscode = CANCELED登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的pubspec.yaml.我正在使用Flutter:

This is my pubspec.yaml. I'm using Flutter:

dependencies:
flutter:
    sdk: flutter

cupertino_icons: ^0.1.2
shared_preferences: ^0.4.2
json_serializable: ^1.2.1
camera: ^0.2.3
path_provider: ^0.4.1
simple_permissions: ^0.1.6
share: ^0.5.3
#Google Sign_In
firebase_auth: ^0.5.20
google_sign_in: ^3.0.5

我无法使用Google登录方法进行身份验证.该窗口正常显示,并且在我的应用抛出错误后:

I cannot authenticate with the Google Sign In method. The window shows up normally and after my app throws a error:

PlatformException(sign_in_failed, Status{statusCode=CANCELED, resolution=null}, null)

还没有在线找到任何解决方案,有人可以帮我吗?

Haven't found any solutions online, can someone help me out?

以下是我的_signIn()方法

Future<FirebaseUser> _signIn() async {

GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
GoogleSignInAuthentication gSA = await googleSignInAccount.authentication;

FirebaseUser user = await auth.signInWithGoogle(
    idToken: gSA.idToken, accessToken: gSA.accessToken);

print("User Name : ${user.displayName}");
return user;
}

调用GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();后我的代码崩溃,所以我猜是我的设置错误.

My code crashes after I call GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn(); so my guess was, that my setup was wrong.

这就是我所说的_signIn()

MaterialButton(
        child: Text("Google Sign-In"),
        onPressed: (){
          _signIn()
            .then((FirebaseUser user) => print(user))
            .catchError((e) => print(e));
        },
      ),

我已经在线删除了Google开发人员控制台上的Firebase-Project,并创建了一个新的Firebase-Project.我也尝试了匿名登录->运行正常

I already deleted the Firebase-Project on the google dev console online and created a new one. Also I tried the anonymous login -> worked fine

感谢您的帮助

推荐答案

好的,所以我设法通过以 release 模式使用APK来解决此问题!

Okay, so I managed to fix this problem with using a APK in release mode!

您必须做什么:

以发布模式构建应用,然后将SHA1或SHA256添加到您的Firebase项目中.

Build your app in release mode and add the SHA1 or SHA256 to your firebase project.

如果您不知道如何准备发布应用,您可以快速完成此操作

If you don't know how to prepare your app for release you can do this quickly.

这篇关于Flutter Firebase Auth/Google_sign_in无法使用statuscode = CANCELED登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆