func getFBUserData(){
if((FBSDKAccessToken.current()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
//everything works print the user data
print(result)
}
})
}
}
输出是:
可选({email =“[email protected]”;“first_name”= Abhishek; id = 1760800260695143;“last_name”= Rajput; name =“Abhishek Rajput”; picture = {data = {height = 200;“is_silhouette “= 0; url =”platform-lookaside.fbsbx.com/platform/profilepic / ... ;; width = 200;};};})
你可以试试
if let res = result as? [String:Any] {
print(res["first_name"])
print(res["last_name"])
print(res["name"])
print(res["email"])
if let picture = res["picture"] as? [String:Any] {
if let data = picture["data"] as? [String:Any] {
print(data["url"])
}
}
}
您也可以使用Codable