Is there anyway to retrieve photos ordered by the number of likes in FQL?
A:
So, I'm guessing this is impossible to do nicely? Here's the ugly solution:
$fql = "SELECT object_id,src_small,link FROM photo WHERE aid = '2389563453799923709' ORDER BY created DESC";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$photos = $facebook->api($param);
if (count($photos) > 0) {
for ($i = 0; $i < count($photos); $i++) {
$objectId = $photos[$i]['object_id'];
$like_count = $facebook->api('/'.$objectId.'/likes');
$photos[$i]['likes'] = count($like_count['data']);
}
}
function cmp($a, $b) {
if ($a['likes'] == $b['likes'])
return 0;
return $a['likes'] > $b['likes'] ? -1 : 1;
}
usort($photos, 'cmp');
ajbeaven
2010-08-15 22:33:10