2

I'm trying to get the user's email address with the followings:

fbLoginManager.logInWithReadPermissions(["email", "public_profile"], handler: { (loginResult, error) -> Void in

                if error != nil {
                    //handle error
                } else if loginResult.isCancelled {
                    //handle cancellation
                } else {
                    //Logged in
                    self.loggedinUser.fbToken = FBSDKAccessToken.currentAccessToken().tokenString

                    var graphReq = FBSDKGraphRequest(graphPath: "me", parameters: nil).startWithCompletionHandler { (connection, result, error) -> Void in
                        if let user = result as? NSDictionary {
                            var email = result.objectForKey("email") as? String
                            var name = result.objectForKey("name") as? String
                            self.loggedinUser.email = email ?? nil
                            self.loggedinUser.fullName = name ?? nil

                        }
                    }
                }
            })

But in the loginResult object the user's email is not sent. Any idea how to solve this?

thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Bence Pattogato
  • 3,752
  • 22
  • 30
  • 1
    I may be wrong, but look at application settings on facebook developers portal - there may be some permission settings that must be enabled as well – heximal Apr 12 '15 at 15:22
  • http://stackoverflow.com/questions/29484345/unable-to-get-email-id-of-logged-person-in-facebook-ios-sdk/29487484#29487484 – Dheeraj Singh Apr 13 '15 at 04:36
  • 1
    I used it "logInWithReadPermissions(["email", "public_profile"]"... , but I still dont get the user's email. – Bence Pattogato Apr 13 '15 at 07:24
  • In the dialog window that pops up do you see that you are requesting email? ie "This app will access your public profile and email " Also as all Facebook users do not need to provide a valid email address one cannot be returned for every user. Per documentation: "The person's primary email address listed on their profile. This field will not be returned if no valid email address is available" – Hey Darren Apr 16 '15 at 08:54
  • @BencePattogato just try using "logInWithReadPermissions(["email"]" as Public_profile is permitted by default. – Dheeraj Singh Apr 17 '15 at 05:08
  • 1
    For SDK 4.4.0, see: http://stackoverflow.com/questions/31314124/get-email-and-name-facebook-sdk-v4-4-0-swift – CularBytes Jul 09 '15 at 17:06

1 Answers1

1

You must provide in the parameters what you want to get:

FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email"]).startWithCompletionHandler({ (connection, result, error) -> Void in

For example to get more than one field:

parameters: ["fields": "id, name, email, picture.type(large)"]
Oliver Apel
  • 1,808
  • 3
  • 19
  • 31