问题
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