how to get user data from Facebook SDK on iOS

徘徊边缘 提交于 2019-12-03 15:57:48

Your GraphRequest was incorrect. If you want to take user data, graphPathe should be "me" and you should request paramter in order to get relationship state and other information. And also you need to request public profile in LogInWithReadPermissons, So In read permisson :-

    let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
    fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web
    fbLoginManager.logInWithReadPermissions(["public_profile","email"], fromViewController: self) { (result, error) -> Void in
        if error != nil {
            print(error.localizedDescription)
            self.dismissViewControllerAnimated(true, completion: nil)
        } else if result.isCancelled {
            print("Cancelled")
            self.dismissViewControllerAnimated(true, completion: nil)
        } else {

        }
    }

And When retrieving information :-

   FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, relationship_status"]).startWithCompletionHandler({ (connection, result, error) -> Void in
            if (error == nil){
                let fbDetails = result as! NSDictionary
                print(fbDetails)
            }
        })

By the way if you want marital status you should use graphPath as "me" not "/{user-id}/family". You can use that for get The person's family relationships.

Get facebook user info update with swift 3

  FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
        if (error == nil){
            let fbDetails = result as! NSDictionary
            print(fbDetails)
        }else{
            print(error?.localizedDescription ?? "Not found")
        }
    })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!