Firebase linkwithcredential 不适用于 Facebook

Posted

技术标签:

【中文标题】Firebase linkwithcredential 不适用于 Facebook【英文标题】:Firebase linkwithcredential not working with Facebook 【发布时间】:2019-11-16 11:48:23 【问题描述】:

我正在处理一段代码,它试图使用 Firebase 将 Facebook 身份验证凭据链接到当前用户。当前用户使用电子邮件/密码创建一个帐户,然后 Facebook 凭据在稍后的时间点链接到该帐户。此代码以前按预期工作,但我们的团队需要更新多个 firestore 依赖项,这似乎破坏了此代码。我不确定问题是什么。

我已尝试检查令牌的内容,但似乎没有任何问题。代码总是在 linkwithcredential 函数处失败。否则,使用 Facebook UI 登录可以完美运行。 linkwithcredential 函数总是吐出相同的错误。

我的代码:

fbLogin.logInWithReadPermissions(['email', 'public_profile'])
.then((result) async 

    print(" == Right Before result.status");
    switch(result.status)
    
        case FacebookLoginStatus.loggedIn:
        
          FacebookAccessToken myToken = result.accessToken;
          print("AccessToken = $myToken.token.toString()");
          AuthCredential credential = FacebookAuthProvider.getCredential(accessToken: myToken.token);
          FirebaseUser us = await FirebaseAuth.instance.linkWithCredential(credential);
         
         //... other cases & error handling
     

输出:

E/MethodChannel#plugins.flutter.io/firebase_auth(26676): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_auth(26676): java.lang.IllegalArgumentException: Given String is empty or null
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(Unknown Source:5)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at com.google.firebase.auth.EmailAuthProvider.getCredential(Unknown Source:2)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.handleLinkWithEmailAndPassword(FirebaseAuthPlugin.java:272)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.onMethodCall(FirebaseAuthPlugin.java:122)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:88)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:219)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at android.os.Looper.loop(Looper.java:181)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at android.app.ActivityThread.main(ActivityThread.java:6981)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/firebase_auth(26676):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
I/flutter (26676): PlatformException(error, Given String is empty or null, null)

pubspec.yaml:

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter_facebook_login:
  flutter:
    sdk: flutter


  cupertino_icons: ^0.1.2
  cloud_firestore: 0.10.1
  firebase_database: ^1.0.5
  firebase_auth: 0.8.1 #^0.6.6
  google_sign_in: ^3.2.4
  firebase_storage: ^1.0.4

  webview_flutter: ^0.3.0


  shared_preferences: ^0.4.3
  cached_network_image: ^0.8.0

  fluttertoast: ^3.0.4
  flutter_auth_buttons: ^0.3.1

  image_picker: ^0.6.0
  image_cropper: ^1.0.1

  auto_size_text: ^1.1.2
  flutter_range_slider: "^1.1.0"
  transparent_image: ^1.0.0
  flutter_image: ^1.0.0

  page_view_indicators: ^1.1.0
  path: any
  intl: ^0.15.8
  stripe_payment: 0.1.0
  geoflutterfire: ^2.0.3
  latlong: ^0.6.1

  firebase_messaging: 4.0.0+4

  flutter_launcher_icons: 0.7.2
  stripe: 1.3.1

义务扑医生:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 10.0.17134.829], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.3)
[√] Connected device (1 available)

• No issues found!

【问题讨论】:

【参考方案1】:

在网上广泛搜索后,这似乎是 Firebase-Auth 的问题。将 Firebase-Auth 从 0.8.1 更新到 0.8.2 解决了这个问题。

【讨论】:

以上是关于Firebase linkwithcredential 不适用于 Facebook的主要内容,如果未能解决你的问题,请参考以下文章

无法从“firebase.js”解析模块“firebase”:在项目中找不到 Firebase

VueJS + Firebase 使用 Firebase 绑定

无法解决:com.google.firebase:firebase-ml-vision:24.1.3;无法解决:com.google.firebase:firebase-core:20.0.2

没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用 Firebase.initializeApp()

如何修复 Firebase 9.0 导入错误? “尝试导入错误:‘firebase/app’不包含默认导出(导入为‘firebase’)。”

Firebase 持久化,清除 Firebase 缓存