简体   繁体   中英

Facebook Graph api get Posts starting from x post (PHP SDK)

Hello i've serched a lot without find an answer to this. is possible to retrieve Fb posts of a certain public page starting from a post id?(for example tomorrow start collecting posts from the last post of today) Let's take for example Bill Gates page

the idea would be to do something similar to:

$id = 216311481960; //Bill's fb id
$last_post = 10153219939326961 // last bill posts   
try {
        $request= $id.'/posts?since='.$last_post.'&access_token=xxxxxxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxx-xxxxxx';
        $search = $fb->get($request);
        if (isset($search)){
            //do something
            }
    }           
catch(Exception $e) {
        echo 'Message: ' .$e->getMessage()."<h1>".$id."</h1>";
}

obviously since parameter has to be a date and that code wont work. Any Idea? Thanks in advance. Edit

i try to search for all posts of a specific Facebook user starting not at a certain date but from a certain post, lets say that today i grab users postid1,postid2,postid3 (postid3 is the last post i've taken, and i save that id) next time i would to grab new posts published after postid3 (since postid3)

You can do it in the url, I just made it work recently. This is from a python code, but the URL should work the same way.

"https://graph.facebook.com/?ids=" + ids[:-1] +
    "&fields=name,posts.limit(5).since(10+days+ago)" +
    "{from,to,full_picture,message,caption,description," +
    "link,name,shares,likes.summary(true)," +
    "comments.summary(true),created_time,is_hidden," +
    "message_tags,place,type,with_tags}")

This will get the last 5 posts from the last 10 days for several page ids. It will also get the total number of likes and comments as summary.

It took me a while to dig this info from the net, I found that since= has changed to since().

I tried to retrieve some reference where it's documented, so far with no success. I'll give you an update if I find it.

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