I need to get user data from Facebook. I successfully receive data such as user name, id, photo, but when I try to query, for example, marital status, I get an empty dictionary in response.

I tried to do different requests, but everywhere I get this result. How can I fix this? My sample code is:

static func getUserRelationship() { if (FBSDKAccessToken.currentAccessToken() != nil) { guard let currentUser = getCurrentFacebookUser() else { return } FBSDKGraphRequest(graphPath: "/\(currentUser.id)/family", parameters: nil, HTTPMethod: "GET").startWithCompletionHandler({ (requestConnection, result, error) in if error == nil { let dictionary = result as! [String : AnyObject] let array = dictionary["data"] print("facebook", result, dictionary, array?.count) } else { print(error.localizedDescription) } }) } else { getDataLogin({ getUserBirthday() }, fails: { (error) in }) } } 

I bring the result to the console

 facebook { data = ( ); } 

    1 answer 1

    I made a wrong request. Here is a working query.

      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 to get information, call the following code.

      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) } })