user1406716
user1406716

Reputation: 9705

How to get list of all Facebook Friends when using Parse?

Following is the output when getFBfriends() is run in the code inside viewDidAppear below:

Output:

Result Dict: {
    data =     (
    );
    summary =     {
        "total_count" = 711;
    };
}
Found 0 friends

The "total_count = 711" is correct but there is not data about the friends. What I am I missing here? Think the permissions are correct.

Code:

class SignUpViewController: UIViewController {
@IBOutlet weak var btn_signIn: UIButton!
@IBAction func action_btnSignIn(sender: AnyObject) {

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

    println("in action_btnSignIn() of SignUpViewController")


    var fbloginView:FBLoginView = FBLoginView(readPermissions: ["email", "public_profile", "user_friends"])

override func viewDidAppear(animated: Bool) {
    if PFUser.currentUser() != nil {
        println("User logged in, so launching Menu Screen")
        //self.performSegueWithIdentifier("launchmenu", sender: self)
        getDBfriends()
    } else {
        println("User NOT logged in")
    }

}
func getDBfriends() {
    var friendsRequest: FBRequest = FBRequest.requestForMyFriends()
    friendsRequest.startWithCompletionHandler{(connection:FBRequestConnection!, result:AnyObject!, error:NSError!) -> Void in
        var resultdict = result as NSDictionary
        println("Result Dict: \(resultdict)")
        var data : NSArray = resultdict.objectForKey("data") as NSArray

        for i in 0..<data.count {
            let valueDict : NSDictionary = data[i] as NSDictionary
            let id = valueDict.objectForKey("id") as String
            println("the id value is \(id)")
        }

        var friends = resultdict.objectForKey("data") as NSArray
        println("Found \(friends.count) friends")
    }
}

}

Upvotes: 1

Views: 2708

Answers (2)

andyrandy
andyrandy

Reputation: 74014

Since v2.0 of the Graph API, you can only get the friends who authorized your App too. The result is correct, none of your friends authorized your App yet so it´s empty and only showing the total amount of friends.

More information: Get ALL User Friends Using Facebook Graph API - Android

Upvotes: 4

Vikram Pote
Vikram Pote

Reputation: 5579

Your permissions are correct, but try to login your app using another fb account you will get that user details in your data response.

Upvotes: 3

Related Questions