【问题标题】:FirebaseUI unable to auth with FacebookFirebaseUI 无法通过 Facebook 进行身份验证
【发布时间】:2018-12-28 16:17:40
【问题描述】:

我在尝试使用 FirebaseUI + Facebook 进行身份验证时收到 "This app is in development mode” 错误。这是通过使应用程序“对公众可用”来解决的。之后,我收到另一个错误,内容为

“用户没有足够的权限查看应用程序。 由于开发者设置,用户无法查看此应用程序”

和日志

2018-07-20 17:56:30.610332+0700 SamuiPlus[79114:33415252] -canOpenURL:URL 失败:“fbauth2:/” - 错误:“操作无法完成。(OSStatus 错误 -10814 .)” 2018-07-20 17:56:30.610602+0700 SamuiPlus [79114:33415252] 由于模拟器错误,退回到在 NSUserDefaults 中存储访问令牌 2018-07-20 17:56:30.612003+0700 SamuiPlus [79114:33415252] -canOpenURL:URL 失败:“fbauth2:/” - 错误:“操作无法完成。(OSStatus 错误 -10814。)” 2018-07-20 17:56:31.913536+0700 SamuiPlus[79114:33502682] TI​​C 读取状态 [12:0x0]: 1:57 2018-07-20 17:56:31.913974+0700 SamuiPlus[79114:33502682] TI​​C 读取状态 [12:0x0]: 1:57 2018-07-20 17:56:32.078459+0700 SamuiPlus[79114:33415252] 信息:显示服务器已启动(协议版本 43)。 2018-07-20 17:56:32.084358+0700 SamuiPlus[79114:33415252] 初始化期间无法成功更新网络信息。 2018-07-20 17:56:32.136652+0700 SamuiPlus[79114:33415252] [App] 如果我们在真正的预提交处理程序中,由于 CA 限制,我们实际上无法添加任何新围栏 2018-07-20 17:56:32.647304+0700 SamuiPlus[79114:33502692] TI​​C 读取状态 [13:0x0]: 1:57 2018-07-20 17:56:32.647397+0700 SamuiPlus[79114:33502692] TI​​C 读取状态 [13:0x0]: 1:57

我遵循了有关在我的应用程序中设置 firebase 和 facebook 的所有官方说明(info.plist、url 类型),在 developer.facebook.com 上尝试了不同的设置,但仍然不明白可能导致问题的原因。 在 android 版本的应用程序上使用 Facebook 登录可以正常工作。

呈现 AuthViewController

func showAuthUI(delegate: FUIAuthDelegate) {
    presentModalViewControllerDerivedFrom({ (_) -> UIViewController in
        let authUI = FUIAuth.defaultAuthUI()
        authUI?.delegate = delegate
        let authViewController = authUI!.authViewController()
        return authViewController
    }, animation: true, completion: nil)
}

FUIAuthDelegate

  extension ProfilePresenter: FUIAuthDelegate {

    func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?){
        if let error = error as NSError? {
            if let errorMessage = error.userInfo["NSLocalizedDescription"] as? String {
                //Show Alert with message provided in 'errorMessage'
                print("auth ui didSignInWith authDataResult, error: \(errorMessage)")
            } else {
                //Show General Alert
                print("auth ui didSignInWith authDataResult, general error")
            }
        } else if let user = authDataResult?.user {
            //Logged in
            // ...
        } else {
            // Unknow State
            print("auth ui didSignInWith authDataResult, unknown state")
        }
    }
}

AppDelegate

  override init() {
        super.init()
        FirebaseApp.configure()
        let authUI = FUIAuth.defaultAuthUI()
    }

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        let authUI = FUIAuth.defaultAuthUI()

        let providers: [FUIAuthProvider] = [
            FUIGoogleAuth(),
            FUIFacebookAuth(permissions: ["public_profile", "email"]),
            FUIPhoneAuth(authUI:FUIAuth.defaultAuthUI()!),
            ]
        authUI?.providers = providers

        return true
    }

  func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String?
        if FUIAuth.defaultAuthUI()?.handleOpen(url, sourceApplication: sourceApplication) ?? false {
            return true
        }
        // other URL handling goes here.
        return false
    }

使用其他提供商登录就可以了。 提前感谢您的帮助。

【问题讨论】:

  • 确保您的 Facebook 应用是公开的并且是实时的。
  • 是的,正如我所说,我公开了我的应用程序。但是让它“活”起来意味着什么?

标签: ios firebase-authentication facebook-login firebaseui


【解决方案1】:

我希望您创建 facebook auth Id 您只想放置此代码并从项目中的任何位置调用此函数。

在 AppDelegate 中

在 applicationDidFinishLaunchingWithOptions 中

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

在 UIApplicationOpenURLOptionsKey 函数中

return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

然后为 FacebookAuth.swift 创建自定义类并为 facebookLogin 创建函数。

    func faceBookLogin() {
      let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
      fbLoginManager.logIn(withReadPermissions: ["email"], from: 
      (self.senderController as! LoginViewController)) { (result, error) -> 
      Void in
      if (error == nil){
       let facebookLoginResult : FBSDKLoginManagerLoginResult = result!
       if (result?.isCancelled)!{
            return
        }
        if(facebookLoginResult.grantedPermissions.contains("email")){
            self.getFacebookUserData()
        }else{

        }
     }else{

        }
      }
  }

然后getFaceBookUserData()的getFaceBookUserData()获取facebook用户数据创建函数,我们得到facebook用户数据。

func getFacebookUserData(){
        if((FBSDKAccessToken.current()) != nil){
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
                if (error == nil){
                    if let userData = result as? NSDictionary{
                        print(userData)
                     }
                }else{

                }
            })
        }
    }

【讨论】:

  • 感谢您的回复。你建议我使用'FBSDKLoginKit',对吧?但正如您在问题中看到的那样,我使用的是 FirebaseUI 解决方案,它显示了不同提供商的登录按钮(一切正常,除了 Facebook)。因此,要尝试您的解决方案,我需要一种方法来处理 FirebaseUI 的“使用 Facebook 登录”按钮以某种方式单击。有什么想法吗?
猜你喜欢
  • 2012-04-01
  • 2014-06-13
  • 1970-01-01
  • 1970-01-01
  • 2014-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多