FQL: Order photos by likes
Is there anyw开发者_StackOverflow社区ay to retrieve photos ordered by the number of likes in FQL?
PLEASE NOTE: I have never played with FQL before, but I need this exact solution yesterday, so I gave it a go!
Try adding references to "like_info" in the first line in the previous answer (maybe like_info is new since you asked this?):
$fql = "SELECT like_info, object_id,src_small,link FROM photo WHERE aid = '2389563453799923709' ORDER BY like_info created DESC";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$photos = $facebook->api($param);
This may well give you answers returned in order from most to least liked. At least, it worked for me! :)
Please note: This solution is no longer require as like_info
has been added to photo
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');
精彩评论