Swift - 如何处理来自 FIRUserInfo 的 FB 验证数据?

Swift - How Can I handle datas from FIRUserInfo for FB Auth?

我刚刚开始使用 Firebase 的新 SDK

let facebookLogin = FBSDKLoginManager()

facebookLogin.logInWithReadPermissions(["email"], fromViewController: self) { (facebookResult: FBSDKLoginManagerLoginResult!, facebookError: NSError!) in

let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)

FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in

之后在获取 Facebook 信息时,

我遇到了一个问题,我怎样才能再次处理所有这些问题?:

 var userData =
                                ["id": FIRAuth.auth()?.currentUser?.uid as! AnyObject,
                                 // "accessToken": credential as! String,
                                 // "provider": user.provider!,
                                 "displayName": user?.providerData["displayName"],
                                 "email": user.providerData["email"] as! String,
                                 "profileImageURL": user.providerData["profileImageURL"] as! String,
                                 // "token": user.token as String,
                                 "createdAt": utcTimeZoneStr]

以下是 FirAuth(当前用户)的属性: https://firebase.google.com/docs/reference/ios/firebaseauth/interface_f_i_r_user#properties

您现在必须添加一个 for ... 来检索 providerData。

if let user = FIRAuth.auth()?.currentUser {
  for profile in user.providerData {
    let providerId = profile.providerId
    let uid = profile.uid;  // Provider-specific UID
    let name = profile.displayName
    let email = profile.email
    let photoUrl = profile.photoURL
  }
} else {
  // No user is signed in.
}