如何从快速3中的FacebookSdk获取生日,城市,手机号码,州,国家

时间:2017-05-29 08:44:59

标签: swift facebook facebook-graph-api

我正在尝试从FacebookSDK获取数据,例如用户信息name, last_name. first_name, email我正在获取此详细信息,但我希望从birthdate, city, mobile number等帐户中获得更多用户的详细信息,我已将所有参数添加到SDK,但我无法获取用户的其他详细信息,任何人都可以帮助我,谢谢,这是我的代码。

     let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
     fbLoginManager.loginBehavior = FBSDKLoginBehavior.web
     fbLoginManager.logIn(withReadPermissions:       
     ["public_profile","email"], from: self) { (result, error) ->
     Void   in
     if error != nil {
      print(error!.localizedDescription)
      self.dismiss(animated: true, completion: nil)
      } else if (result?.isCancelled)! {
      print("Cancelled")
      self.dismiss(animated: true, completion: nil)
       } else {
       }
    }
    //id,name,birthday,email,last_name,location
     FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id,  
       name, first_name, birthday, email ,       
     location"]).start(completionHandler:
       { (connection, result, error) -> Void in
        if (error == nil){
            let fbDetails = result as! NSDictionary

            print("fb details\(fbDetails)")

        }
    })

`

1 个答案:

答案 0 :(得分:2)

你可以得到如下

let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"first_name,email, picture.type(large)"])

            graphRequest.start(completionHandler: { (connection, result, error) -> Void in

                if ((error) != nil)
                {
                    print("Error: \(error)")
                }
                else
                {
                    let data:[String:AnyObject] = result as! [String : AnyObject]
                    print(data)

                }
            })