简体   繁体   English

使用Facebook graph API以逆向时间顺序检索状态注释

[英]Using the Facebook graph API to retrieve comments for statuses in REVERSE chronological order

I'm trying to retrieve comments for statuses from Facebook's Graph API in REVERSE chronological order, that is the newest comments should be on top. 我正在尝试以REVERSE的时间顺序从Facebook的Graph API中检索状态的注释,这是最新的注释应该放在最上面。 I am not sure if this is even possible. 我不确定这是否可能。

I know Facebook orders posts in chronologically descending order by default, and comments are chronologically ascending (oldest on top) by default. 我知道Facebook默认情况下按时间顺序降序排列帖子,默认情况下,评论按时间顺序升序排列(最早出现在顶部)。 By default, I mean in Facebook.com and the way they are retrieved from the API. 默认情况下,我的意思是在Facebook.com中以及从API中检索它们的方式。

Using the Graph API I am able to retrieve statuses in descending order, but comments are returned in ascending order. 使用Graph API,我可以按降序检索状态,但是注释按升序返回。 I'd like to get the comments in reverse order from the API without having to sort them in my program. 我想以相反的顺序从API获取注释,而不必在程序中对它们进行排序。 The reason being is that the program is limited to the # of comments it will download, so setting the limit=xx will actually retrieve the first xx comments, rather than the newest xx comments. 原因是该程序仅限于它将下载的注释数,因此设置limit = xx实际上将检索前xx条注释,而不是最新的xx条注释。 This is no good for me because if a status has 500 comments, and xx=100, it will always retrieve the same set of comments (first 100 to be posted). 这对我没有好处,因为如果状态包含500条评论,且xx = 100,则它将始终检索同一组评论(前100条要发布)。

The best parameter for the Html request that I can find is 'order_by' which looks for a time/date param (updated_time), but this does not actually work since it is already ordered by the updated_time (but ascending). 我可以找到的Html请求的最佳参数是“ order_by”,它查找时间/日期参数(updated_time),但这实际上不起作用,因为update_time已经对其进行了排序(但是升序)。 I would like to specify order_by descending updated_time, if possible. 如果可能的话,我想通过降序update_time来指定order_。

Any help will be appreciated. 任何帮助将不胜感激。

There is no direct way of doing this with the API but one way to get this working is to retrieve all the comments for the status, assign them to an array, and loop through the results in reverse order. 使用该API并没有直接的方法,但是要实现这一工作的一种方法是检索状态的所有注释,将它们分配给数组,然后以相反的顺序循环遍历结果。

The below example gets the last status update from the Guinness Ireland page and assigns all the messages into an array. 下面的示例从Guinness Ireland页面获取最新状态更新,并将所有消息分配到一个数组中。 Once we have this array we can spit out the results with a loop. 一旦有了这个数组,我们就可以用循环吐出结果。

Example: 例:
$data = file_get_contents('https://graph.facebook.com/GuinnessIreland/statuses?limit=1&access_token=' . $ACCESS_TOKEN); $ data = file_get_contents('https://graph.facebook.com/GuinnessIreland/statuses?limit=1&access_token='。$ ACCESS_TOKEN);

$comments = json_decode($data); $ comments = json_decode($ data);
$messages = ($comments->data[0]->comments->data); $ messages =($ comments-> data [0]-> comments-> data);

for ($counter = count($messages); $counter >= 0; $counter = $counter - 1) { for($ counter = count($ messages); $ counter> = 0; $ counter = $ counter-1){
echo $messageArray[$counter]->message; echo $ messageArray [$ counter]-> message;
echo $messageArray[$counter]->created_time; echo $ messageArray [$ counter]-> created_time;
} }

You can get the comments using get request through this url.. you will get json response. 您可以通过此URL使用get请求获取评论。您将获得json响应。

https://graph.facebook.com/ "StatusID"/comments?limit=500&access_token="accessToken" https://graph.facebook.com/ “ StatusID” / comments?limit = 500&access_token =“ accessToken”

StatusID=132343454_54346345 userID statusid accessToken=user Access token. StatusID = 132343454_54346345 userID statusid accessToken =用户访问令牌。

you ll get JSOn response. 您将得到JSOn响应。 get all the details like user who commented, commentid, message... you will get JSON response . 获取所有详细信息,例如评论用户,commentid,消息...的用户,您将获得JSON response。 Parse them.check the comment on next page by connecting url in "next" string in the "page" object at the bottom of the JSON Page. 解析它们。通过在JSON页面底部的“页面”对象中的“下一个”字符串中连接url,检查下一页上的注释。 Enjoy. 请享用。

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

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