简体   繁体   English

如何获得Facebook帖子的所有评论和喜欢?

[英]How to get all comments and likes for a facebook post?

If you have the read_stream permission and you get the posts of a facebook user, for each post you only get the top X comments and top X likes. 如果您拥有read_stream权限并且获得了Facebook用户的帖子,那么对于每个帖子,您只能获得前X个评论和前X个喜欢。 Is there a way to paginate through the likes/comments and get them all? 有没有办法通过喜欢/评论进行分页并获取所有内容?

If there's any FQL query which would return ALL likes or comments for a post, or let me page through them 20 or so at a time, that would work too. 如果有任何FQL查询会返回帖子的所有喜欢或评论,或者让我一次翻阅20个左右,那也可以。

Edited: 编辑:

You have to get each status to get all comments/likes on that status. 您必须获得每个状态才能获得该状态的所有评论/喜欢。 If you have a specific post that you want the comments for: 如果您有特定帖子,则需要评论:

$post     = '100003978045030_105596009583000';
$comments = array();
$done     = false;
$options  = array();
$path     = '/' . $post . '/comments';

while(!$done){
    try{
        $data = $facebook->api($path, 'GET', $options);
    } catch(FacebookApiException $e) {
        echo $e->getMessage();
        $data = null;
        $done = true;
    }
    if(!is_null($data)){
        $comments = array_merge($comments, $data['data']);
        if(isset($data['paging']['next']) && !empty($data['paging']['next'])){
            $parts = parse_url($data['paging']['next']);
            $path  = $parts['path'];
            parse_str($parts['query'], $options);
        } else {
            $done = true;
        }
    }
}

print_r($comments);

In FQL, you just have to query the comment or like table: 在FQL中,您只需查询注释类似表:

SELECT post_id, text, fromid FROM comment 
   WHERE post_id IN 
      (SELECT post_id FROM stream WHERE source_id = USER_OR_PAGE_ID
       AND comments.count > 0 )
   LIMIT 0, 100

This will give you the first 100 results (but less than 100 may be returned, since those not visible to you will be filtered out). 这将为您提供前100个结果(但可能会返回少于100个结果,因为您将看不到那些不可见的结果)。

Note that the like table is hobbled for page streams. 请注意,类似的表格被阻塞用于页面流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM