0

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.

Community
  • 1
  • 1
Nazik
  • 8,696
  • 27
  • 77
  • 123

2 Answers2

3

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.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Ok I understood. I need to get all my friends email address even if they are not authorized my app. Is it possible? – Nazik Jan 11 '16 at 12:55
  • 2
    No, that is of course not possible. As already said, can not get “all friends” any more – and you can not get the email addresses of random users at all. You can only get the email for users that log into your app and grant it the according permission themselves. – CBroe Jan 11 '16 at 13:03
  • exactly, what CBroe said. you can only get the email of users who authorized your App with the "email" permission. – andyrandy Jan 11 '16 at 13:14
  • Please see my edited question, if I simply call /me/friends, it's not working. I authorized with two facebook users, both of them are friends in facebook, But I can't see their details in the response. – Nazik Jan 11 '16 at 13:26
  • it only works if both friends authorized the app with user_friends – andyrandy Jan 11 '16 at 14:11
2

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

technerd
  • 14,144
  • 10
  • 61
  • 92