Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this error when accessing Facebook information of user?

Why is it giving me the error 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 I am trying to access user information like friends, email, etc. How do I fix the error? Below is the login plus the permissions to get access to user info.

@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.")
        }
    })
}
like image 822
blee Avatar asked Sep 15 '15 01:09

blee


1 Answers

I don't think that FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter is actually an error. It is just a Log. If you will run the code and set a break point you will find that, error is actually nil and you will be able to successfully compile the code and see the else portion of the code getting executed.

Now, you are trying to access the name of Facebook user but not passing name in the fields. That is why you will get name as null. Pass name as list of parameters.

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

Or here:

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

Now, you will be able to fetch name, email and friends of the Facebook user.

like image 50
Cityzen26 Avatar answered Nov 10 '22 00:11

Cityzen26