shoujo_sm shoujo_sm - 6 months ago 106
iOS Question

Get FBSDKLoginManagerLoginResult's email and name

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")

}
}

Answer

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)");

            }
        }
        }
    }
Comments