Bartłomiej Semańczyk Bartłomiej Semańczyk - 7 months ago 13
Swift Question

How to get user info after login with FBSDKLoginKit in iOS?

I have created a button:

let button = FBSDKLoginButton(frame: CGRectMake(100, 100, 300, 50))
button.readPermissions = ["public_profile", "user_friends"]
view.addSubview(button)


then tap it and make some things to login. Where do I receive data after login? How to get access to them?

NOTE

The question is about
FBSDKLoginKit
, not
Facebook-ios-sdk
.

Answer

Simple implementation for received token and userID after login:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {

    if error != nil {
        print("error")
    } else if result.isCancelled {
        print("cancelled")
    } else {
        print("token: \(result.token.tokenString)")
        print("user_id: \(result.token.userID)")
    }
}
Comments