I am trying to retrieve email id after fb login in my app. However I am getting an error when i try to get the value from result.
The error is:Type 'Any?' has no subscript members
.
func fetchProfile()
{
print("Fetch Profile")
let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start { (connection, result, error) in
let email = result["email"] as? String //Type 'Any?' has no subscript members error occurs here.
}
}
change this
let email = result["email"] as? String
into
guard let resultNew = result as? [String:Any]
let email = resultNew["email"] as! String
full answer
let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start { (connection, result, error) in
guard let resultNew = result as? [String:Any]
let email = resultNew["email"] as! String
}
For Swift 3.
change this-->
let email = result["email"] as? String
Into -->
if let fbemail = (result as AnyObject)["email"]! as? String
{
print(fbemail)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With