Get FBSDKLoginManagerLoginResult by Email and Name

I use Facebook user login to get user email and public profile, but I only get it. Is there any other code that I missed? Most online tutorials are in Obj-C or are outdated. I am using Swift for this project.

RESULT: '<FBSDKLoginManagerLoginResult: 0x7fe6f8c1d510>' 

Here is my custom button code

 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") } } 
+6
source share
3 answers

Use FBSDKGraphRequest to get user information.

 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)"); } } } } 
+15
source

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)"); } }) 
+3
source

For Swift 2.1:

 let login = FBSDKLoginManager() login.logInWithReadPermissions(["email", "public_profile"]){ result, error in if error != nil { print("error") }else if(result.isCancelled){ print("result cancelled") }else{ let fbRequest = FBSDKGraphRequest(graphPath:"me", parameters: nil); fbRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in if error == nil { print("User Info : \(result)") } else { print("Error Getting Info \(error)"); } } } } 
+1
source

Source: https://habr.com/ru/post/986562/


All Articles