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

我是研究僧i 提交于 2019-12-22 12:38:16

问题


I have just started Firebase's new 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

After that while getting Facebook Informations,

I have encountered a problem, How Can I handle all of them again?:

 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]

回答1:


You have to add a for ... in to retrieve the providerData now.

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.
}



回答2:


Here are the properties of FirAuth (current user): https://firebase.google.com/docs/reference/ios/firebaseauth/interface_f_i_r_user#properties



来源:https://stackoverflow.com/questions/37316332/swift-how-can-i-handle-datas-from-firuserinfo-for-fb-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!