简体   繁体   中英

Get posts that created in the past 24hr of a facebook page using php sdk 4

Facebook in versions after 2.0 will not support FQL anymore. So I've to change from FQL to graph api instead.

My old FQL code is..

SELECT source_id,post_id,message,like_info.like_count,comment_info.comment_count,share_info.share_count,permalink,created_time,attachment.media FROM stream WHERE source_id = "--page_id--" AND actor_id = "--page_id--" AND created_time>--time_start-- AND created_time<--time_end-- ORDER BY like_info.like_count DESC

and this is my graph api code using phpsdk4 which transfer from the fql code above and it's not complete (because I don't know how to do next step).

require_once 'facebookphpsdk4/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;

$access_token = 'xxx|yyy';
FacebookSession::setDefaultApplication( 'xxx','yyy' );
$session = new FacebookSession($access_token);
$request = new FacebookRequest(
    $session,
    'GET',
    '/page_id?fields=posts{id,shares,message,likes.summary(true),comments.summary(true)}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();

I need ....

  • permalink's post
  • large size images attachment's post
  • to filter period of time (created in the past 24 hours)
  • to order by (DESC) amount of like or order by created_time

How can I get all of this without using fql ? Thank you for your answer.

There are several issues about getting the same result with the Graph API instead of FQL:

  • There's no permalink field
  • You can't explicitly specify the attachments to be large
  • You can't apply an ordering. Default ordering should be by created_time though

To specify the time filter, you can use the URL parameters since and until :

GET /{page_id}/posts?fields=id,message,shares,object_id,likes.summary(true),comments.summary(true),attachments{media}&since=1423440000&until=1423526399

This should giveyou all posts from today for a specific page.

You could create a permalink by concatenating imho:

https://www.facebook.com/{page_id}/posts/{object_id}

See:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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