0
votes

I'm trying to get Facebook friends list of a specific user using a access token.

https://developers.facebook.com/docs/graph-api/reference/friend-list/

But how to get the friend-list-id?

So far this is an example of all I am able to get.

https://graph.facebook.com/fbID/friends?access_token=appid|appsecret

1
Friend lists are only the lists users can create on Facebook, to “sort” their friends into different categories. From this endpoint, you will get the list id and name only – you will not get which users are on those lists. /me/friends is what you need to get the friends of the user that are users of your app as well.CBroe

1 Answers

1
votes

I think you want to use me/friends after they've logged in. The response will be an Array you can loop over, so you can get each User id property and make more calls to FB.api() using the id, if desired.

This is probably what you want to do:

fbAsyncInit = function(){
  FB.init({
    appId: 'yourAppIdHere',
    version: 'v2.5'
  });
  FB.getLoginStatus(function(response){
    if(response.status === 'connected'){
      FB.api('me/friends', function(a){
        for(var i=0,l=a.length; i<l; i++){
          /* make a call for each friend with more .api calls - a is array of User objects - props seen here https://developers.facebook.com/docs/graph-api/reference/user/ */
          FB.api(a[i].id, function(r){
          });
        }
      });
    }
    else{
      location = 'https://www.facebook.com/dialog/oauth?client_id=replaceThisWithAppId&redirect_uri='+location;
      // change out replaceThisWithAppId above
    }
  });
}
(function(d, s, id){
  var js, fjs = d.getElementsByTagName(s)[0];
  if(d.getElementById(id)){return;}
  js = d.createElement(s); js.id = id;
  js.src = '//connect.facebook.net/en_US/sdk.js';
  fjs.parentNode.insertBefore(js, fjs);
})(document, 'script', 'facebook-jssdk');