如何在Flutter中使用Facebook进行身份验证?

时间:2019-07-30 07:21:45

标签: facebook flutter firebase-authentication

我正在使用Facebook进行首次身份验证。所以,我很困惑。实际上,我能够从Facebook身份验证中获取数据,但是当我尝试获取电子邮件地址时,却无法从数据中获取电子邮件地址。

我搜索了很多有关此问题的信息,但找不到实际的解决方案。

    var facebookLogin = new FacebookLogin();
    var result = await facebookLogin.logInWithReadPermissions(['email']);

    switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        final token = result.accessToken.token;
        AuthCredential fbCredential = FacebookAuthProvider.getCredential(
            accessToken: token);
        FirebaseAuth.instance.signInWithCredential(fbCredential).then((
            FirebaseUser user) {
          assert(user.displayName!=null);
          assert(!user.isAnonymous);
          print("User"+user.toString());
          print("Name"+user.displayName);
          print("email"+user.email);
          // do something...
        });
        break;

显示数据异常:

   UserFirebaseUser({providerData: [{uid: 0**********, providerId: firebase, 
    displayName: G**** , photoUrl: 
    https://graph.facebook.com/1**********/picture}, {email: man*****@gmail.com, 
    uid: 105*********3, providerId: facebook.com, displayName: G****, photoUrl: 
    https://graph.facebook.com/18888***41023/picture}], providerId: firebase, 
    photoUrl: https://graph.facebook.com/105********3/picture, isAnonymous: 
    false, uid: 0x581JD7Iof*********Dm1, creationTimestamp: ********1117, 
    lastSignInTimestamp: 1564*******0, isEmailVerified: false, displayName: 
    G***})
I/flutter ( 3546): NameG*****a
E/flutter ( 3546): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Invalid argument(s)
E/flutter ( 3546): #0      _StringBase.+ (dart:core-patch/string_patch.dart:260:57)
E/flutter ( 3546): #1      _MyAppState.facebookSignin.<anonymous closure> (package:flutter_app/Screens/LoginScreen.dart:143:24)
E/flutter ( 3546): #2      _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 3546): #3      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 3546): #4      _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
E/flutter ( 3546): #5      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
E/flutter ( 3546): #6      Future._propagateToListeners (dart:async/future_impl.dart:668:32)
E/flutter ( 3546): #7      Future._complete (dart:async/future_impl.dart:473:7)
E/flutter ( 3546): #8      _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
E/flutter ( 3546): #9      _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:28:18)
E/flutter ( 3546): #10     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:294:13)
E/flutter ( 3546): #11     FirebaseAuth.signInWithCredential (package:firebase_auth/src/firebase_auth.dart)
E/flutter ( 3546): <asynchronous suspension>
E/flutter ( 3546): #12     _MyAppState.facebookSignin (package:flutter_app/Screens/LoginScreen.dart:137:31)
E/flutter ( 3546): <asynchronous suspension>
E/flutter ( 3546): #13     _MyAppState.build.<anonymous closure> (package:flutter_app/Screens/LoginScreen.dart:577:31)
E/flutter ( 3546): #14     _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511:14)
E/flutter ( 3546): #15     _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:566:30)
E/flutter ( 3546): #16     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
E/flutter ( 3546): #17     TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9)
E/flutter ( 3546): #18     TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:177:9)
E/flutter ( 3546): #19     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:436:9)
E/flutter ( 3546): #20     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 3546): #21     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 3546): #22     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:221:19)
E/flutter ( 3546): #23     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22)
E/flutter ( 3546): #24     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 3546): #25     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 3546): #26     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 3546): #27     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 3546): #28     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 3546): #29     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 3546): #30     _invoke1 (dart:ui/hooks.dart:233:10)
E/flutter ( 3546): #31     _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5)
E/flutter ( 3546): 

0 个答案:

没有答案