Reputation: 548
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
Upvotes: 0
Views: 699
Reputation: 1246
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
Upvotes: 0
Reputation: 164437
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.
Upvotes: 2