I'm trying to get information through the facebook sdk but so far I'm getting only the id and the name of the user, although I'm sure there is an email available, as it is my account. I've been looking at several answer here but none of them solved my problem so far. What am I doing wrong, and why is it not returning more data as I am requesting several permissions?
Here is my code:
fbLoginManager.logInWithReadPermissions(["public_profile", "email", "user_friends", "user_about_me", "user_birthday"], handler: { (result, error) -> Void in
if ((error) != nil)
{
// Process error
println("There were an error: \(error)")
}
else if result.isCancelled {
// Handle cancellations
fbLoginManager.logOut()
}
else {
var fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.contains("email"))
{
println(fbloginresult)
self.returnUserData()
}
}
})
And the function to get the user data:
func returnUserData()
{
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
// Process error
println("Error: \(error)")
}
else
{
println("fetched user: \(result)")
if let userName : NSString = result.valueForKey("name") as? NSString {
println("User Name is: \(userName)")
}
if let userEmail : NSString = result.valueForKey("email") as? NSString {
println("User Email is: \(userEmail)")
}
}
})
}
Which returns:
fetched user: {
id = 55555555;
name = "Kali Aney";
}
User Name is: Kali Aney