7

有谁知道为什么无论给定的图形状态更新对象有多少评论,它都会将评论限制在 25 条?我有一种感觉,它只返回对象实际评论的“样本”。如何在不使用 FQL API 的情况下强制它全部获取?

4

1 回答 1

1

这正是 Graph API 的工作方式。查看 API 文档。您一次获得 25 个,并且必须循环遍历它们。您可以将批处理中最后一条评论的时间戳(created_time)用作下一次 Graph API 调用中的参数,也可以使用该offset参数。这就是我一直在做的事情。我在使用created_time. 这是我的 C# 测试应用程序中的一个示例。忽略对对象的引用,该PostComment对象只是我创建的用于保存要提取的数据的数据结构。魔术(以及我引用的过程)在于传递给图形 API 调用的参数:

parameters.Add("offset", numPostComments);
parameters.Add("limit", 25);

我相当确定您可以将“限制”设置为 25 或以下的任何值。

do
{
    foreach (var comment in comments.data)
        {
            numPostComments++;
            PostComment pc = new PostComment();
            pc.Post_ID = p.Id;
            pc.Facebook_ID = comment.id;
            pc.From = comment.from.name;
            if (comment.likes != null)
                pc.Likes = (int)comment.likes;
            pc.CommentDate = DateTime.Parse(comment.created_time);
            pc.CommentText = comment.message;
            p.Comments.Add(pc);
        }
        // Create new Parameters object for call to API
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("offset", numPostComments);
        parameters.Add("limit", 25);

        // Call the API to get the next block of 25
        comments = client.Get(string.Format("{0}/comments", p.Facebook_ID), parameters);
} while (comments.data.Count > 0);
于 2011-09-22T12:27:22.397 回答