I have implemented the facebook login functionality for my app.
After you click the log in button(which has its class set to FBSDKLoginButton) and you login in with username and password, the text of the button changes to logout, which is great. However, I do not receive the profile picture or the name of the user form facebook.
Below are my FBSDKLoginButtonDelegate methods. I have put a print action in the loginButton method and it does not print, so it must not enter this method.
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
{
print("does it enter here?")
FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"first_name, last_name, picture.type(large)"]).startWithCompletionHandler { (connection, result, error) -> Void in
let strFirstName: String = (result.objectForKey("first_name") as? String)!
let strLastName: String = (result.objectForKey("last_name") as? String)!
let strPictureURL: String = (result.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as? String)!
self.lblName.text = "Welcome, \(strFirstName) \(strLastName)"
self.ivUserProfileImage.image = UIImage(data: NSData(contentsOfURL: NSURL(string: strPictureURL)!)!)
}
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!)
{
let loginManager: FBSDKLoginManager = FBSDKLoginManager()
loginManager.logOut()
ivUserProfileImage.image = nil
lblName.text = ""
}
Can you help me? What am I missing that when I log in with facebook, I do not enter the loginButton method?
Thank you in advance.
I have found the answer myself and I'll leave here in case anybody else needs it. I was missing this: btnFacebook.delegate = self I have put this line of code into viewDidLoad method and now I get the profile picture and the name of the user from facebook.