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.
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.