Nazik
Nazik

Reputation: 8444

Graph Path and Parameters for getting facebook friends list in Swift

I'm using the below code to get the friends list,

let fbRequest = FBSDKGraphRequest(graphPath:"/me/friends", parameters:["fields": "friendlists"]);
    fbRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in

        if error == nil {

            print("Friends are : \(result)")

        } else {

            print("Error Getting Friends \(error)");

        }
    }

It's always returning empty array.

OutPut:

 Friends are : {
 data =     (
 );
}

If I try sending a simple call to /me/friends, FBSDKGraphRequest(graphPath:"/me/friends", parameters:nil) an error logged as below,

FBSDKLog: starting with Graph API v2.4, GET requests for //me/friends should contain an explicit "fields" parameter.

So I referred this answer for the above Parameters.

I authorized the app with two facebook users, both of them are friends in facebook, But I can't see their details in the response.

Still, empty array is returning.

Anyone please check whether the graph path and parameters I mentioned in the code is correct.

The privacy settings in the facebook account for friends list is public.

Upvotes: 0

Views: 3185

Answers (2)

technerd
technerd

Reputation: 14504

You can get only authorized friends with your application.

Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.

Check this link for deatiled information.

You can get only count of friends linked to your account, but you can not get any other detail of friends without permission.

enter image description here

Upvotes: 2

andyrandy
andyrandy

Reputation: 73984

There is a difference between "friends" and "friendlists". What you want to get is the list of "friends", not the "friendlists". You don´t need the "fields" parameter for that, a simple call to /me/friends is enough.

That being said, you can only get friends who authorized your App too, so if none of your friends authorized your App, you will get an empty array. Of course you need to authorize with the user_friends permission, and your friends must authorize your App with that permission too.

Upvotes: 3

Related Questions