Receive posts and comments from the Facebook page

I want to get all posts from this facebook page along with the corresponding comments.

I wrote this code (application details were confused, replace them with your own to run it).

<?php require_once('facebook.php'); $facebook = new Facebook(array( 'appId' => 'MY_APP_ID', 'secret' => 'MY_APP_SECRET', 'cookie' => true, )); $pages = array( "stackoverflow" => 11239244970 ); $result = $facebook->api(array( 'method' => 'fql.multiquery', 'queries' => '{ "posts": "select post_id, source_id, actor_id, target_id, likes, message from stream where source_id = '.$pages["stackoverflow"].'", "comments": "select post_id, text, username, fromid from comment where post_id in (select post_id from #posts)" }' )); echo json_encode($result); ?> 

posts returns the expected results, but comments returns only one comment.

This example requests the stackoverflow facebook page

Comment returned from comments request, "Joined"! (from this post ). I can not understand what is special about this comment.

Anyone though?

+4
source share
1 answer

I tried to find a solution playing with Graph Api

 https://graph.facebook.com/me/fql?q=select message, comments from stream where source_id = 11239244970 

works, but when returning comments, it returns only the last 2. This excludes how Facebook itself displays the stream and comments with the link “View all XX comments”.

To request posts and comments together, you can use:

 https://graph.facebook.com/fql?q={"posts":"select post_id,message, comments from stream where source_id = 11239244970","comments": "select post_id, text, username from comment where post_id in (select post_id from #posts)"}&access_token=... 

According to Facebook:

Each query of the stream table is limited to the previous 30 days or 50 messages, whichever is greater, however you can use time-specific fields such as created_time along with FQL statements (for example, <or>) to receive a much larger number of messages .

+1
source

All Articles