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

2024-04-25 19:11:23 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用Facebook图形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)

如果我不使用limit,我只能得到25个帖子,这是默认值。如果我把限制在一些高值,比如500,我只能得到168个帖子。这168个职位从“2013-12-20”到“2014-01-09”。所以实际上我在‘2013-01-01’到‘2013-12-19’之间漏掉了帖子。在


Tags: httpsgithubcomapi图形数量facebooksdk
1条回答
网友
1楼 · 发布于 2024-04-25 19:11:23

根据documentation

When you make an API request to a node or edge, you will usually not receive all of the results of that request in a single response. This is because some responses could contain thousands and thousands of objects, and so most responses are paginated by default.

您可以通过向键中的url发出请求来获取所有结果:paging -> next

结果格式为-

{
  "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"
  }
}

(在我提到的链接中搜索“基于时间的分页”,了解更多详细信息)

相关问题 更多 >