iOS:Firebase 和 facebook 帐户工具包登录

标签 ios swift firebase firebase-authentication facebook-account-kit

我想问问是否有人可以指导我如何使用 Facebook 的帐户工具包为 firebase 添加电话登录的示例或解释。

我正在从 facebook account kit 获取 accessToken,然后尝试像这样授权

fileprivate func authorizeWithAccessToken(_ accessToken: AKFAccessToken?, phoneNumber: AKFPhoneNumber?, error: NSError?) {
    guard let accessToken = accessToken else {
        return
    }

    FIRAuth.auth()?.signIn(withCustomToken: accessToken.tokenString) { (user, error) in
        if (error != nil) {
            print(error?.localizedDescription)
        } else {
            print("User logged in")
        }
    }
}

但是我得到了错误:

"The custom token format is incorrect. Please check the documentation." UserInfo={NSLocalizedDescription=The custom token format is incorrect. Please check the documentation., error_name=ERROR_INVALID_CUSTOM_TOKEN})

这是我的代币:

EMAWeGCejpgSijO0ncgBYl7HxLTZBy0rWrwaHihA81ZB286EEPhdZCtDSWZAnajp8pmX10E1ZCJDV7Ghwz0NrxRMhZCgSPzZC9imjbamk8bvv2AZDZD

最佳答案

为什么您使用 customTokens 进行 Facebook 身份验证,而不是使用 Firebase 为 Facebook 提供的内置凭证方法?

使用 Facebook 库创建凭证对象而不是 token :

let credential = FIRFacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)

并将此对象传递给 signIn(with: ) 方法。

FIRAuth.auth()?.signIn(with: credential) { (user, error) in
    if let err = error {
      print(err?.localizedDescription)
     return
   }

   // Do your stuff here....
}

可以找到使用 Firebase 和 Facebook 的完整文档 here

关于iOS:Firebase 和 facebook 帐户工具包登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42211014/

相关文章:

swift - 如何在 WKWebView 完成加载之前运行函数?

ios - 在 Ipad 上使用 UITableview Longpress 进行操作表操作的最佳方式是什么

ios - MessageAppExtension : how to load sticker images from assets to MSStickerBrowserView?

firebase - flutter firebase 使用 refreshToken 自动刷新用户 session

firebase - Cloud Firestore-实时监听器更新是否算作读取操作?

ios - 拦截 UITabBar 点击

ios - Objective-C : Value of array inexplicably resets every time button is clicked

ios - 详细 View UITableView - 在 segue 之前传递数据

ios - 空指针的取消引用

firebase - 在cli上部署云功能, "Firebase config variables are not available."