简体   繁体   English

Facebook实时更新

[英]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. 我正在创建一个应用程序,用户通过该应用程序在Facebook墙或用户的时间线页面上共享特定帖子。 This is done via the Javascript sdk and Facebook graph api. 这是通过Javascript sdk和Facebook图形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. 我想知道的是,我需要收集我在数据库中存储的id共享帖子上的所有评论和喜欢。

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. 然后我运行一个cron,它再次使用图形api来获取Facebook上特定订阅源(id来自db)的帖子和评论。

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. 就像有人对Feed发表评论一样,它会向我的链接发送请求,该链接会保存/更新我的数据库中的评论。 if not, let me know that is my cron thing the best way to do this. 如果没有,让我知道这是我的cron事情,这是最好的方法。 or is there another way for it 还是有另一种方式

Facebook does indeed give you the ability to get real-time updates, as discussed in this document . Facebook确实让你能够获得实时更新,正如本文档中所讨论的那样。

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. 根据这个文档,它看起来不像你可以获得有关帖子的评论/喜欢的更新,你只能获得User对象的特定字段/集合的更新,而不是特定的帖子。

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.. 没有这样的能力可以实时更新它,你可以用cron或更新评论来做,喜欢依靠刷新按钮..

$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 在$ POST_URL中键入: https://graph.facebook.com/POST_ID + POST_ID

in $post_data['likes']['count'] you will have likes count $post_data['likes']['count']你会喜欢数

in $post_data['comments']['count'] you will have comments count $post_data['comments']['count']你会有评论数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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