13

Is this possible to get all my friends likes?? Now, I'm getting this by 2 steps:

  1. Getting all my friends list
  2. By iterating those list I'm getting all individuals Likes,

but it seems very big process, anybody have idea to improve the performance for this task?

maxgrinev
  • 281
  • 2
  • 4
  • 12

3 Answers3

14

At last I found it after 2 weeks looking at Facebook API documentation

FB.api("/likes?ids=533856945,841978743")

FB.api("me/friends",{
  fields:'id',
  limit:10
},function(res){
  var l=''
  $.each(res.data,function(idx,val){
     l=l+val.id+(idx<res.data.length-1?',':'')
  })
  FB.api("likes?ids="+l,function(res){
      console.log(res);
  })
})
brasofilo
  • 25,496
  • 15
  • 91
  • 179
dupdup
  • 772
  • 1
  • 6
  • 14
5

Using FQL is going to be faster than looping through the Graph API results. You can get the ID of the pages your friends like, but unfortunately FQL does not return info other than that (ie the name). Take a look at the following.

This assumes you are using the PHP SDK with the friends_likes permission.

// hold on to your user ID
$user_id = $facebook->getUser();

// query your friend's likes based on their ID
$query = "SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = $user_id)";
$result = $fb->api(array(
  'method' => 'fql.query',
  'query' => $query,
));

// optionally group the results by each friend ID
function arraySort($input, $sortkey){
  foreach ($input as $key => $val) {
    $output[ $val [ $sortkey ] ][] = $val;
  }
  return $output;
}
$friendLikes = arraySort($result,'uid');

// output the results
echo sprintf('<pre>%s</pre>', print_r($friendLikes,TRUE));

The benefit of this is that you only make one API call. You will have to make separate calls to get the friend names and another for the liked page details, but you have the IDs to work with now in a straight forward approach.

sakibmoon
  • 2,026
  • 3
  • 22
  • 32
Carson
  • 4,541
  • 9
  • 39
  • 45
0

I believe that is the only way. I looked at this problem a few weeks ago. Don't think they've changed the API.

http://developers.facebook.com/docs/reference/api/

EDIT: I'm not sure I understand well enough what you mean... If you mean that you want to get a list of the posts that a user likes, what you have to do is this:

  1. Get all the posts by friends
  2. Check if likes any of their posts
  3. Get all the posts by
  4. Check if likes any of his/her own posts
  5. Combine the results

Is that what you want?

Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156
  • Thank for answer. But actually I cannot implement even this way! How can I get posts that an user liked? I cannot find any way to do it. There is only "likes" in http://developers.facebook.com/docs/reference/api/user/ but those are pages that the user likes, not posts. – maxgrinev Jan 27 '11 at 12:32
  • 1
    I cannot believe there is a more efficient way to do this. I've just played with FQL a lot and to my level of knowledge I believe one really needs to get the friends list first, then do an extra likes call for each of the friends. This can be a very very long process. Is this really the only way? – Sven Haiges Jan 02 '12 at 14:46
  • @Sven I was tackling a similar problem a while back (http://stackoverflow.com/questions/4874014/how-can-i-get-friendship-details-in-facebook-graph-api), and it seems like no one really knows the answer. I guess if it's not documented we should just assume that it's not there. – Enrico Susatyo Jan 02 '12 at 23:12
  • Thx. I'll be thinking about thsi the next hours. One idea I have is to first get all friends ids. Then, using a multi-request, I'll try to get the likes. If that works I'll let everyone know. – Sven Haiges Jan 03 '12 at 08:58