Search code examples
javafacebookfacebook-comments

Get new comments of facebook post (since parameter)


I am trying to get comment of a fanpage since a given time. But it seems like the since parameter is ignored.

try {
    $attachments = array('access_token' => $profile['access_token'], 'since' => strtotime('2013-03-07T18:13:57+0000'));
    $comments = $facebook->api("$id/comments", 'GET', $attachments);
    print_r($comments);
} catch (FacebookApiException $e) {
    error_log($e);
}

Isn´t that possible?


Solution

  • No, since doesn't work with every table. A solution is to use FQL:

    SELECT id, time, text 
      FROM comment
     WHERE object_id = POST_ID
           AND time > UNIX_TIME 
     LIMIT 50 
    OFFSET 0
    

    (replace POST_ID and UNIX_TIME)


    You can loop on this query while incrementing the OFFSET by 50.

    The first group will give the 50 most recent comments, the second the 50 previous and so on. But each group contains comments ordered in chronological order.

    You can stop looping once a query sends less than 50 results.