使用Facebook Graph API获取有限数量的帖子

0 投票
1 回答
2736 浏览
提问于 2025-04-18 00:22

我在用Facebook Graph API查询一个Facebook页面(这里是“沃尔玛”)时,得到的帖子数量有限。我使用的是https://github.com/pythonforfacebook/facebook-sdk

graph = facebook.GraphAPI(oath_access_token)
feed = graph.get_object('/walmart/' + 'posts', since='2013-01-01', until='2014-01-10', limit=500)

如果我不设置限制,默认只会得到25个帖子。如果我把限制设置得很高,比如500,我也只得到168个帖子。这168个帖子是从‘2013-12-20’到‘2014-01-09’的。所以实际上,我错过了‘2013-01-01’到‘2013-12-19’之间的帖子。

1 个回答

2

根据文档的说明:

当你向某个节点或边发起API请求时,通常不会在一次响应中收到所有的结果。这是因为有些响应可能包含成千上万的对象,所以大多数响应默认是分页的。

你可以通过请求键为paging -> next的URL来获取所有结果。

结果的格式是-

{
  "data": [
     ... Endpoint data is here
  ],
  "paging": {
    "previous": "https://graph.facebook.com/me/feed?limit=25&since=1364849754",
    "next": "https://graph.facebook.com/me/feed?limit=25&until=1364587774"
  }
}

(在我提到的链接中搜索“基于时间的分页”可以获取更多细节)

撰写回答