This question already has an answer here:
I am using Facebook SDK for login and fetching data at my end but unable to solve the issue I am facing challenges related to syntax
func fetchProfile() {
let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start(completionHandler: { (connection, user, requestError) -> Void in
if requestError != nil {
print(requestError)
return
}
var email = user["email"] as? String
let firstName = user["first_name"] as? String
let lastName = user["last_name"] as? String
self.nameLabel.text = "\(firstName!) \(lastName!)"
var pictureUrl = ""
if let picture = user["picture"] as? NSDictionary, let data = picture["data"] as? NSDictionary, let url = data["url"] as? String {
pictureUrl = url
}
})
}
In the line var email = user["email"] as ? String
i getting error as type any? has no transcript.
Try this:
You need to convert the
user
typeAny
to type Dictionary[String:AnyObject]
, then only you can use subscripts to extract value from it.