Flutter:PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,null) [英] Flutter: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

查看:167
本文介绍了Flutter:PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,null)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Flutter应用程序,我试图允许用户登录其Gmail,因为我希望能够列出他们的电子邮件。当我按下 LoginButton 时,我会收到Gmail登录的提示,并输入了凭据,但随后返回的屏幕LoginButton ,然后我遇到错误:

I have a Flutter app and I am trying to allow users to sign into their Gmail because I want to be able to list out their emails. When I press my LoginButton, I get prompted with a Gmail login, and I enter in my credentials, but then it goes back to the screen with the LoginButton and I am faced with the error:

未处理的异常:PlatformException(sign_in_failed,com.google.android。 gms.common.api.ApiException:10:,null)

我尝试过的事情:


  • 已将 google-services.json 添加到/ android / app,并已添加 GoogleService-Info.plist 到ios / Runner。

  • 启用gmail进行Firebase身份验证。

  • 在我的Firebase身份验证中添加调试SHA1和SHA256。

  • 填写OAuth同意书(我做了其他所有事情。我不知道这是否会影响它。)

  • Added google-services.json to /android/app and added GoogleService-Info.plist to ios/Runner.
  • Enabling gmail for Firebase authentication.
  • Adding my debug SHA1 and SHA256 to my firebase authentication.
  • Filling out the OAuth consent form (I did this after everything else. I don't know if that would affect it.)

有什么想法吗?谢谢!

这是我的代码:

class AuthService {
  final GoogleSignIn _googleSignIn = GoogleSignIn();
  final FirebaseAuth _auth = FirebaseAuth.instance;
  final Firestore _db = Firestore.instance;

  Observable<FirebaseUser> user;
  Observable<Map<String, dynamic>> profile;
  PublishSubject loading = PublishSubject();

  AuthService() {
    user = Observable(_auth.onAuthStateChanged);

    profile = user.switchMap((FirebaseUser u) {
      if (u != null) {
        return _db
            .collection('users')
            .document(u.uid)
            .snapshots()
            .map((snap) => snap.data);
      } else {
        return Observable.just({});
      }
    });
  }

  Future<FirebaseUser> googleSignIn() async {
    loading.add(true);
    GoogleSignInAccount googleUser = await _googleSignIn.signIn();
    GoogleSignInAuthentication googleAuth = await googleUser.authentication;
    final AuthCredential credential = GoogleAuthProvider.getCredential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );
    FirebaseUser user = (await _auth.signInWithCredential(credential)).user;

    updateUserData(user);
    print("signed in " + user.displayName);

    loading.add(false);
    return user;
  }

  void updateUserData(FirebaseUser user) async {
    DocumentReference ref = _db.collection('user').document('user.uid');

    return ref.setData({
      'uid': user.uid,
      'email': user.email,
      'photoURL': user.photoUrl,
      'displayName': user.displayName,
      'lastSeen': DateTime.now()
    }, merge: true);
  }

  void signOut() {
    _auth.signOut();
  }
}

final AuthService authService = AuthService();



Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
I/FA      ( 4974): Tag Manager is not found and thus will not be used
W/d.memail.memai( 4974): Accessing hidden method Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J (light greylist, reflection)
W/d.memail.memai( 4974): Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (light greylist, reflection)
W/d.memail.memai( 4974): Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray; (light greylist, reflection)
W/d.memail.memai( 4974): Accessing hidden method Landroid/util/LongArray;->get(I)J (light greylist, reflection)
Syncing files to device Android SDK built for x86...
I/OpenGLRenderer( 4974): Initialized EGL, version 1.4
D/OpenGLRenderer( 4974): Swap behavior 1
D/        ( 4974): HostConnection::get() New Host Connection established 0xd831cb40, tid 5016
D/EGL_emulation( 4974): eglCreateContext: 0xec485d80: maj 2 min 0 rcv 2
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/        ( 4974): HostConnection::get() New Host Connection established 0xd3f22780, tid 5005
D/EGL_emulation( 4974): eglCreateContext: 0xec485a80: maj 2 min 0 rcv 2
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485a80: ver 2 0 (tinfo 0xec483c50)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
I/d.memail.memai( 4974): Background concurrent copying GC freed 35614(5MB) AllocSpace objects, 27(1068KB) LOS objects, 50% free, 1856KB/3MB, paused 498us total 214.123ms
I/OpenGLRenderer( 4974): Davey! duration=719ms; Flags=1, IntendedVsync=65710145267, Vsync=66060145253, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=66062704600, AnimationStart=66062759800, PerformTraversalsStart=66062789600, DrawStart=66070699600, SyncQueued=66071765200, SyncStart=66073102800, IssueDrawCommandsStart=66074268300, SwapBuffers=66323835100, FrameCompleted=66431085200, DequeueBufferDuration=26966000, QueueBufferDuration=372000, 
E/EnhancedIntentService( 4974): binding to the service failed
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485a80: ver 2 0 (tinfo 0xec483c50)
W/ActivityThread( 4974): handleWindowVisibility: no activity for token android.os.BinderProxy@b021561
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglCreateContext: 0xec485b40: maj 2 min 0 rcv 2
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485b40: ver 2 0 (tinfo 0xec483c50)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485b40: ver 2 0 (tinfo 0xec483c50)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
E/flutter ( 4974): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
E/flutter ( 4974): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter ( 4974): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:344:48)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #3      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:218:23)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #4      GoogleSignIn._addMethodCall (package:google_sign_in/google_sign_in.dart:257:20)
E/flutter ( 4974): #5      GoogleSignIn.signIn (package:google_sign_in/google_sign_in.dart:324:48)
E/flutter ( 4974): #6      AuthService.googleSignIn (package:memail/auth.dart:33:58)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #7      LoginButton.build.<anonymous closure>.<anonymous closure> (package:memail/main.dart:86:46)
E/flutter ( 4974): #8      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter ( 4974): #9      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
E/flutter ( 4974): #10     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 4974): #11     TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter ( 4974): #12     TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter ( 4974): #13     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter ( 4974): #14     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter ( 4974): #15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter ( 4974): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 4974): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 4974): #18     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 4974): #19     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 4974): #20     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 4974): #21     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 4974): #22     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 4974): #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 4974): #24     _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter ( 4974): #25     _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
E/flutter ( 4974): 


推荐答案

我也遇到了这个问题。就我而言,我尝试实现 GoogleSignIn 在我的一个已经处于生产级别的应用程序中。

I also faced this issue..In my case, I tried to implement GoogleSignIn in one of my apps that is already at production level..

当我尝试执行此操作时。.我也遇到了相同的错误。. APIException:10 ..看起来您的情况也一样。.

When I tried to do this..I also got the same error.. APIException: 10.. looks like yours is also the same case..

我尝试了很多次..但最后,我最终做出让步,决定在我的应用中不包含 GoogleSignIn

I tried many times..but, finally, I ended up compromising and decided not to include GoogleSignIn in my app..

但是,..我又解决了通过向 FireBase项目添加2个 SHA1 键。.one用于 debug模式和其他用于释放模式 ..

But, again..I solved it..by adding 2 SHA1 keys to the FireBase Project..one for the debug mode and other for release mode..

如果我只调试 SHA1 键。它在发行版模式下不起作用,但在 debug 模式,如果我只放 release SHA1键,那么它在 debug 模式下不起作用,但可以正常工作在 release 模式下。

If I put only debug SHA1 key..it is not working in release mode but working fine in debug mode and if I put only release SHA1 key..it is not working in debug mode but working fine in release mode .

不知道为什么会这样ing ..但是它正在发生..并且以某种方式可以正常工作。.

Not sure why is it happening..but it is happening..and somehow it is working fine..

确定..now ..什么是 debug release 键..不是一样的..我如何获得它们..?

Ok..now..what is debug and release key.. aren't they the same..how do I get them..?

在这里。

命令提示符中转到项目。.然后 cd android ,然后键入。.

Go to your project in Command Prompt.. then cd android and then type..

gradlew signingReport

它将提供 SHA1 键。.

有一个密钥是由调试密钥库生成的,另一个是由 release密钥库生成的。 。

There is one key generated by the debug keystore and the other by the release keystore..

将它们都添加到项目中。并且它(希望)正常工作..就像对我一样。

Add both of them to the project..and it works(hopefully)..as it did for me..

希望它会有所帮助。

注意:我正在使用 Windows ..不确定是否在 Mac 上生成密钥的过程也相同。

Note: I'm using Windows..not sure if it is the same process to generate keys on Mac as well..

这篇关于Flutter:PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,null)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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