使用 Firebase 在 Flutter 中实现 Google Signin 后出现平台异常错误

问题描述 投票:0回答:1

这是我继续使用 Google 的代码。
这是我的代码,还有错误消息,我得到, [使用firebase实现google提供商在flutter中登录,googleSignIn flutter包

这些是错误消息:

W/Auth    (21814): [GoogleAuthUtil] [GoogleAuthUtil] error status:UNKNOWN with method:getTokenWithDetails
I/flutter (21814): catchErrorHappened
I/flutter (21814): catchErrorHappened: PlatformException(exception, ERROR, null, null)
I/flutter (21814): PlatformException code: exception
I/flutter (21814): PlatformException message: ERROR
I/flutter (21814): PlatformException details: null

这是我的代码:

  Future<void> _continueWithGoogle() async {
    print("contiune with google started");
    try {
      final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();

      if (googleUser == null) {
        print('Google sign-in canceled');
        return;
      }

      final GoogleSignInAuthentication googleAuth =
          await googleUser.authentication;

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

      print('accessToken');
      print(credential.accessToken);

      UserCredential userCredential =
          await _auth.signInWithCredential(credential);

      if (userCredential.user != null) {
        print('Sign in successful');
      } else {
        _showErrorMessage('Sign in failed. Please try again.');
      }
    } on FirebaseAuthException catch (e) {
      print("Error in continue with google");
      print("withoutError");
      print('FirebaseAuthException: ${e.message}');
      _showErrorMessage(e.message ?? 'An error occurred. Please try again.');
    } on PlatformException catch (e) {
      print("catchErrorHappened");
      print("catchErrorHappened: $e");
      print('PlatformException code: ${e.code}');
      print('PlatformException message: ${e.message}');
      print('PlatformException details: ${e.details}');
      _showErrorMessage(e.message ?? 'An error occurred. Please try again.');
    }
  }
flutter firebase google-signin
1个回答
0
投票
final GoogleSignInAccount? googleUser = await GoogleSignIn(scopes: ["profile", "email"]).signIn();
© www.soinside.com 2019 - 2024. All rights reserved.