我想從Facebook
檢索用戶的數據和存儲在firebase
特定的數據並顯示它UILabel
Facebook的SDK和火力地堡
請提供任何有用的鏈接,如果有任何。
我的代碼:
fileprivate func setupFacebookButton() {
// add facebook button
let loginButton = FBSDKLoginButton()
loginButton.frame = CGRect(x: 24, y: 535, width: 165, height: 44)
loginButton.delegate = self
loginButton.readPermissions = ["email", "public_profile" , "user_birthday", "user_location"]
view.addSubview(loginButton)
}
和
let accessToken = FBSDKAccessToken.current()
guard let accessTokenString = accessToken?.tokenString else { return }
let credentials = FacebookAuthProvider.credential(withAccessToken: accessTokenString)
Auth.auth().signIn(with: credentials, completion: { (user, error) in
if error != nil {
print("Something went wrong with our FB user: ", error ?? "")
return
}
print("Successfully logged in with our user: ", user ?? "")
})
let requestParameters = ["fields": "name, email, birthday, gender, location"]
//location first_name, gender, age_range, user_birthday
FBSDKGraphRequest(graphPath: "/me", parameters: requestParameters).start { (connection, result, err) in
if err != nil {
print("Failed to start graph request:", err ?? "")
return
}
print(result ?? "")
}
輸出:
{
birthday = "09/21/1987";
email = "[email protected]";
gender = male;
id = 1520497814669566;
location = {
id = 106065422766757;
name = "User city, User Country";
};
name = "User Name";
}
Successfully logged in with our user: <FIRUser: 0x6080000c87a0>
你試圖存儲Facebook的什麼信息?它是整個「結果」還是僅僅是某些數據? – eshirima
@EmilDavid只有整個結果 –