4

我想从给定的 facebook 页面中检索所有帖子以及相关的评论。

我写了这段代码(应用程序细节被混淆了,用你自己的替换以运行它)。

<?php
require_once('facebook.php');
$facebook = new Facebook(array(
    'appId'  => 'MY_APP_ID',
    'secret' => 'MY_APP_SECRET',
    'cookie' => true,
));

$pages = array(
    "stackoverflow" => 11239244970
);

$result = $facebook->api(array(
    'method' => 'fql.multiquery',
    'queries' => '{
        "posts": "select post_id, source_id, actor_id, target_id, likes, message from stream where source_id = '.$pages["stackoverflow"].'",
        "comments": "select post_id, text, username, fromid from comment where post_id in (select post_id from #posts)"
    }'
));

echo json_encode($result);
?>

posts返回预期结果,但comments只返回一条评论。

此示例查询stackoverflow facebook 页面

查询返回的评论comments是“已加入!” (来自这篇文章)。我不知道这条评论有什么特别之处。

有什么想法吗?

4

1 回答 1

1

我试图找到一个使用 Graph Api 的解决方案

https://graph.facebook.com/me/fql?q=select message, comments from stream where source_id = 11239244970

正在工作,但在返回评论时,它只返回最后 2 条。Facebook 本身如何通过“查看所有 XX 条评论”链接显示流和评论。

要同时查询帖子和评论,可以使用:

https://graph.facebook.com/fql?q={"posts":"select post_id,message, comments from stream where source_id = 11239244970","comments": "select post_id, text, username from comment where post_id in (select post_id from #posts)"}&access_token=...

根据脸书:

流表的每次查询仅限于前 30 天或 50 个帖子,以较大者为准,但是您可以使用特定于时间的字段,例如 created_time 以及 FQL 运算符(例如 < 或 >)来检索更大范围的帖子。

于 2012-03-01T22:04:47.580 回答