FQL:按喜欢订购照片

时间:2010-07-28 02:57:33

标签: facebook facebook-fql

无论如何要检索按FQL中的喜欢数量排序的照片吗?

2 个答案:

答案 0 :(得分:2)

请注意:我之前从未使用过FQL,但我需要这个昨天的确切解决方案,所以我试了一下!

尝试在上一个答案的第一行添加对“like_info”的引用(也许like_info是新的,因为你问过这个?):

$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);

这可能会给你答案,从大多数到最不喜欢的顺序返回。至少,它对我有用! :)

答案 1 :(得分:1)

请注意:不再需要此解决方案,因为like_info已添加到照片


所以,我猜这不可能做得很好吗?这是丑陋的解决方案:

$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');