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.