I am using Facebook custom login to get user's email and public profile but I only get this. Is there any else code that I have missed out? Most of the online tutorials are in Obj-C or outdated already. I am using Swift for this project.
RESULT: '<FBSDKLoginManagerLoginResult: 0x7fe6f8c1d510>' 
Here are my code for the custom button
let login = FBSDKLoginManager()
    login.logInWithReadPermissions(["email", "public_profile"]){ result, error in
        println("RESULT: '\(result)' ")
        if error != nil {
            println("error")
        }else if(result.isCancelled){
            println("result cancelled")
        }else{
            println("success")
        }
    }
Use FBSDKGraphRequest to get user info.
let login = FBSDKLoginManager()
    login.logInWithReadPermissions(["email", "public_profile"]){ result, error in
        println("RESULT: '\(result)' ")
        if error != nil {
            println("error")
        }else if(result.isCancelled){
            println("result cancelled")
        }else{
            println("success Get user information.")
            var fbRequest = FBSDKGraphRequest(graphPath:"me", parameters: nil);
        fbRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in
            if error == nil {
                println("User Info : \(result)")
            } else {
                println("Error Getting Info \(error)");
            }
        }
        }
    }
Swift 3+
FBSDKGraphRequest(graphPath:"me", parameters: ["fields":"email"]).start(completionHandler: { (connection, result, error) in
    if error == nil {
      print("User Info : \(result)")
    } else {
      print("Error Getting Info \(error)");                        
    }
})
Swift 4 code in Xcode 10:
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
        if error != nil{
            //Failed Login
        } else if result.isCancelled{
            //User cancelled
        } else{
            //Successful login
            FBSDKGraphRequest(graphPath:"me", parameters: ["fields" : "email,name,picture"]).start(completionHandler: { (connection, result, error) in
                if error == nil {
                    print("User Info : \(result)")
                } else {
                    print("Error Getting Info \(error)");
                }
            })
        }
    }
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