簡體   English   中英

PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10:, null, null) 嘗試在 flutter 中使用 googleSignIn 時

[英]PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) When trying to use googleSignIn in flutter

我已經閱讀了我能找到的所有 Stackoverflow 問題和 github 問題,但沒有任何效果。

我正在嘗試使用 GoogleSignIn 登錄和驗證 Calender 范圍。

我有 -

  • 使用 Android Studio 中的 gradle 任務獲取我的 SHA-1 和 SHA256 指紋。
  • 在 Google 雲控制台中將 SHA-1 添加到我的 OAuth2 憑證中。
  • 向我的 firebase 控制台添加了 SHA-1 和 SHA256 密鑰
  • 這樣做之后替換了 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

我在手機和模擬器上都在調試和發布模式下檢查了它。

有誰知道我錯過了什么?

這是我的代碼:

這是在 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): 

因此,經過 2 天的嘗試,我找到並遵循了本教程並讓它工作

我還想添加其他有用的信息:

如果您在使用從Google Play 控制台下載的應用時遇到Google 登錄問題:PlatformException(sign_in_failed, z1.b: 10:, null, null)

您需要將 SHA-1 從 Google Play 控制台添加到 Firebase

在此處輸入圖像描述

錯誤代碼 10 表示 SHA 密鑰錯誤。 因此,一旦您使用此命令“ ./gradlew signingReport ”創建了 SHA 密鑰。 將生成許多 SHA 密鑰。 Select 與您的 jks 文件相對應的 SHA 密鑰,並放在 firebase 控制台的 android 應用程序部分下,本教程對我有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM