为什么我在访问用户的Facebook信息时会收到此错误?

时间:2015-09-15 01:59:49

标签: ios swift facebook-graph-api parse-platform

为什么它会给我错误2015-09-14 20:56:31.773 Musec[7207:3288153] FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter我试图访问朋友,电子邮件等用户信息。如何修复错误?以下是登录以及访问用户信息的权限。

@IBAction func loginWithFB(sender: AnyObject) {

    var permissions = [ "public_profile", "email", "user_friends"]

    PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions,  block: {  (user: PFUser?, error: NSError?) -> Void in
        if let user = user {

            if user.isNew {
                println("User signed up and logged in through Facebook!")
                self.performSegueWithIdentifier("success", sender: self)
                //let params = ["fields": "name, email, friends"]
                let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "name, email, friends"])
                graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

                if ((error) != nil)
                {
                    // Process error
                    println("Error: \(error)")
                }
                else
                {
                    //get username
                    let userName : NSString = result.valueForKey("name") as! NSString
                    println(userName)
                    //get Facebook ID
                    let email: NSString = result.valueForKey("email") as! NSString
                    println(email)
                    //get facebook friends who use app
                    let friendlist: NSString = result.valueForKey("friends") as! NSString
                    println(friendlist)

                }
                })

            } else {
                println("User logged in through Facebook!")
                self.performSegueWithIdentifier("success", sender: self)
            }
        } else {
            println("Uh oh. The user cancelled the Facebook login.")
        }
    })
}

1 个答案:

答案 0 :(得分:7)

我不认为FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter实际上是一个错误。它只是一个日志。如果您将运行代码并设置断点,您会发现,错误实际上是nil,您将能够成功编译代码并看到代码的else部分被执行。< / p>

现在,您正在尝试访问name Facebook用户,但未在name中传递fields。这就是为什么你会namenull。将name作为参数列表传递。

let params = ["fields": "name, email, friends"] <----- This line

或者在这里:

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

现在,您将能够获取Facebook用户的name, email and friends