Get email and name Facebook SDK v4.4.0 Swift

前端 未结 10 2119
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 02:22

TL;TR: How do I get the email and name of a user that is logged in on my app using the facebook SDK 4.4

So far I have managed to get login working, now I can get the

10条回答
  •  温柔的废话
    2020-12-08 02:38

    In Swift, you can make a Graph request(as shown by @RageCompex) from the login button's didCompleteWithResult callback.

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
        {
            print(result.token.tokenString) //YOUR FB TOKEN
            let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"email,name"], tokenString: result.token.tokenString, version: nil, HTTPMethod: "GET")
            req.startWithCompletionHandler({ (connection, result, error : NSError!) -> Void in
                if(error == nil)
                {
                    print("result \(result)")
                }
                else
                {
                    print("error \(error)")
                }
            })
    }
    

提交回复
热议问题