android - PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException : 10: , null, null) 尝试在 flutter 中使用 googleSignIn 时

标签 android firebase flutter google-api google-signin

我已经阅读了我能找到的所有 Stackoverflow 问题和 github 问题,但没有任何效果。

我正在尝试使用 GoogleSignIn 登录和验证 Calender 范围。

我有-

  • 使用 Android Studio 中的 gradle 任务获取我的 SHA-1 和 SHA256 指纹。
  • 将 SHA-1 添加到我在 Google 云控制台中的 OAuth2 凭据。
  • 将 SHA-1 和 SHA256 key 添加到我的 firebase 控制台
  • 在这样做之后替换了 google-services.json 文件。
  • classpath 'com.google.gms:google-services:4.3.10' 添加到我项目的 build.gradle 文件中, 并在我的应用程序的 build.gradle 文件中 apply plugin: 'com.google.gms.google-services'
  • 在所有这些之后运行 flutter clean

我在手机和模拟器上都在调试和 Release模式下检查了它。

有谁知道我错过了什么吗?

这是我的代码:

这是在 initState() 中:

    _signIn.onCurrentUserChanged.listen((user) async {
      if(user != null) {
        d.log('${user.id}, ${user.email}, ${user.photoUrl}');
        final authUser = (await _signIn.authenticatedClient());
        if(authUser == null) {
          d.log('no user');
        } else {
          _calendar = CalendarApi(authUser);
        }
      }
    });

这是我按下登录按钮的时候:

  void _onPress() {
    if(_calendar == null) {
      _signIn.signIn();
    } else {
      ...
      });
    }
  }

这是我的 flutter doctor -v:

[√] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.19041.572], locale en-IL)
    • Flutter version 2.10.3 at D:\flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (11 days ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at C:\Users\Itay Rabin\AppData\Local\Android\sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)

[√] IntelliJ IDEA Community Edition (version 2020.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] Connected device (3 available)
    • AOSP on IA Emulator (mobile) • emulator-5554 • android-x86    • Android 9 (API 28) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.19041.572]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 99.0.4844.51

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

这是我得到的错误:

E/flutter ( 4782): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)
E/flutter ( 4782): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 4782): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter ( 4782): <asynchronous suspension>
E/flutter ( 4782): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:377:43)
E/flutter ( 4782): <asynchronous suspension>
E/flutter ( 4782): #3      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:248:30)
E/flutter ( 4782): <asynchronous suspension>
E/flutter ( 4782): #4      GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart:378:5)
E/flutter ( 4782): <asynchronous suspension>
E/flutter ( 4782): 

最佳答案

我还想添加额外的有用信息:

如果您对从 Google Play 管理中心 下载的应用Google 登录 有问题: PlatformException(sign_in_failed, z1.b: 10:, null, null)

您需要将 SHA-1 从 Google Play 控制台添加到 Firebase

enter image description here

关于android - PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException : 10: , null, null) 尝试在 flutter 中使用 googleSignIn 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71462188/

相关文章:

java - Android 版 OUI 查找数据库

python - 如何在后台运行时使用flutter应用程序截屏

firebase - 我如何使用从其他页面获取的值

android - 使用任务从 Firestore 中多次读取文档引用

java - Firebase android Task<T> 成功后不返回任何内容

flutter - 带有 Google 登录帐户的 Google API

flutter - 来自另一个类的Flutter调用集状态

android - 在着色器上使用多个 SurfaceTexture

Android:如何将滚动布局转换为位图

android - ListView 不显示在模拟器中,但显示在 Android studio 中?