FBSDKLog:从Graph API v2.4开始,对/ me / permissions的GET请求应该包含一个明确的“fields”参数

时间:2015-09-12 14:00:15

标签: ios xcode facebook swift

有谁知道我收到此错误的原因?我有一个字段参数集。我是快速和编码的新手,任何帮助将不胜感激。

let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender"])

    // start the request:
    graphRequest.startWithCompletionHandler({

        // void in means that it will return nothing upon completion
        (connection, result, error) -> Void in

        // do an error check
        if error != nil {


            print(error)


        } else if let result = result {

            PFUser.currentUser()?["gender"] = result["gender"]
            PFUser.currentUser()?["name"] = result["name"]
            PFUser.currentUser()?.save()


            // use the user's FB id to get their public profile. First make their id a string:
            let userId = result["id"] as! String
            // next go to the internet and get their photo from FB:
            let facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "/picture?type=large"

1 个答案:

答案 0 :(得分:0)

有一种方法可以让你获得对象“我”,之后你可以获取它的每一个值

let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
        if (error) != nil   {
            NSLog("Error: \(error)")
            ActivityIndicatorWithLabel.shared.hideProgressView()
            view.makeToast(message: "We are unable to connect to Facebook. Please try after sometime")
        }else{
            self.facebookData(result)
        }
    })

在此结果中,我们获得了用户的所有详细信息 这是一种从这个

获取的方法
func facebookData(result: AnyObject){
    NSLog("Sending Login from facebook call")
    var missingFields:[String] = []
    userSocialDetailsGlobal.loginType = "facebook"
    userSocialDetailsGlobal.socialId = result.valueForKey("id") as! String
    userSocialDetailsGlobal.firstName = result.valueForKey("first_name") as! String
    userSocialDetailsGlobal.lastName = result.valueForKey("last_name") as! String

    userSocialDetailsGlobal.socialToken = FBSDKAccessToken.currentAccessToken().tokenString
}

struct userSocialDetailsGlobal {
    static var socialId: String = String()
    static var firstName: String = String()
    static var lastName: String = String()
    static var loginType: String = String()
    static var socialToken: String = String()
}