1

我正在尝试使用 FBSDKGraphRequest 填充文本字段。名字/姓氏和电子邮件不是问题,但说到位置,我似乎只能得到“德克萨斯州奥斯汀”。我似乎无法将单个值取出并放入 textFields。

在下面的代码中,城市文本字段填充了“德克萨斯州奥斯汀”。我怎么能得到'奥斯汀'城市,然后在状态文本字段中得到'德克萨斯'?

        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name, last_name, location"]).start(completionHandler: { (connection, result, error) -> Void in
            if let error = error {
                self.alertTheUser(title: "Error", message: error.localizedDescription)
                print(error)
            }else{
                let fbDetails = result as! NSDictionary
                let location : NSDictionary! = fbDetails.value(forKey: "location") as! NSDictionary
                print(fbDetails)
                self.registerEmailField.text = fbDetails.value(forKey: "email") as? String
                self.registerFirstNameField.text = fbDetails.value(forKey: "first_name") as? String
                self.registerLastNameField.text = fbDetails.value(forKey: "last_name") as? String
                self.registerCityField.text = location.value(forKey: "name") as? String
            }
        })
4

1 回答 1

0

忘记清除这个了。

FBSDKGraphRequest 中的位置应如下所示。

FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name, last_name, location{location}"]).start(completionHandler: { (connection, result, error) -> Void in

然后,您可以单独访问各个位置值。

let locationContents: NSDictionary! = location.value(forKey: "location") as! NSDictionary
self.registerCityField.text = locationContents.value(forKey: "city") as? String
self.registerStateField.text = locationContents.value(forKey: "state") as? String
self.registerCountryField.text = locationContents.value(forKey: "country") as? String
于 2018-03-26T22:04:07.113 回答