简体   繁体   中英

Facebook Real time updates

i am creating an application via which a user shares a specific post on the facebook wall or the user's timeline page. This is done via the Javascript sdk and Facebook graph api. I want to know is that i need to collect all the comments and the likes on that shared post whose id i store in the database.

then i run a cron which uses the graph api again to get the posts and comments on a specific feed (id from db) on facebook.

but i want to know is, that, is there any way for a real time update. Like if someone comments on the feed it send a request to my link and that link saves / update the comment in my database. if not, let me know that is my cron thing the best way to do this. or is there another way for it

Facebook does indeed give you the ability to get real-time updates, as discussed in this document .

According to this document how ever, it doesn't look like you can get updated about the comments/likes of a post, you can only get updates to specific fields/collections of the User object, not a specific post.

There is no such ability to upadate it in real time, you may do it with cron or do update comments, likes count upon refresh button..

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $POST_URL);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1)    Gecko/20100101 Firefox/10.0.1");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

$file_content = curl_exec($ch);   
curl_close($ch); 
if ($file_content === false) {
   //post was delete or something else
} else {
  $post_data = json_decode($file_content, true);
}

in $POST_URL you type: https://graph.facebook.com/ + POST_ID

in $post_data['likes']['count'] you will have likes count

in $post_data['comments']['count'] you will have comments count

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