1

有没有办法检索按 FQL 中的点赞数排序的照片?

4

2 回答 2

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

这很可能会按照从最喜欢到最不喜欢的顺序返回给您的答案。至少,它对我有用!:)

于 2013-01-28T23:28:25.633 回答
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');
于 2010-08-15T22:33:10.147 回答