Onur Tuna Onur Tuna - 11 months ago 52
Swift Question

Can not fetch email from Facebook in Swift

EDIT: The problem with this question is a bit silly. As in the answer the problem is that I have not given the parameters which I want.

I can not get through with it anymore :) What can be the problem?

func returnUserData()
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

if ((error) != nil)
// Process error
print("Error: \(error)")
print("fetched user: \(result)")
let userName : NSString = result.valueForKey("name") as! NSString
print("User Name is: \(userName)")
let userEmail : NSString = result.valueForKey("email") as! NSString
print("User Email is: \(userEmail)")

I call the function like that:

func loginButton(loginButton: FBSDKLoginButton!,
didCompleteWithResult result: FBSDKLoginManagerLoginResult!,
error: NSError!) {
print("User Logged In")

if ((error) != nil)
// Process error
} else if result.isCancelled {
// Handle cancellations
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.grantedPermissions.contains("email")
// Do work

I get the error:

enter image description here

My problem is about the fatal error. However, I am kindly waiting for the comments on 2nd and 3rd lines of the output. Because, I get this output every time but the app runs correctly.

Answer Source

You must specify the parameters for the request.

let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "first_name, last_name, email"])