Python Can';t通过API对过去1000条Facebook评论进行分页

Python Can';t通过API对过去1000条Facebook评论进行分页,python,facebook-graph-api,Python,Facebook Graph Api,我在Facebook上发了一篇帖子,至少有4000条确认的公众评论。但我只能得到980个 每次清除900后,我都会出现以下错误: Traceback (most recent call last): File "fb_pcf_temp.py", line 41, in <module> next = decoded['paging']['next'] KeyError: 'next' 回溯(最近一次呼叫最后一次): 文件“fb_pcf_temp.py”,第41行,在

我在Facebook上发了一篇帖子,至少有4000条确认的公众评论。但我只能得到980个

每次清除900后,我都会出现以下错误:

Traceback (most recent call last):
    File "fb_pcf_temp.py", line 41, in <module>
    next = decoded['paging']['next']
KeyError: 'next'
回溯(最近一次呼叫最后一次):
文件“fb_pcf_temp.py”,第41行,在
next=已解码['paging']['next']
KeyError:“下一个”
我的代码是:

#!/usr/bin/env python
# encoding: utf-8
"""
postgrabber.py

Created by ian on 2012-09-24.
Copyright (c) 2012 __MyCompanyName__. All rights reserved.
"""

import sys
import os
import ogp
import config
import httplib
import simplejson as json
import requests

getData = ogp.facebookQueries()
post_id = "145061248901557_381440708596942"

def getmore(nexturl):
    access_token = getData.authenticate()
    theFeedUrl = nexturl + "&" + access_token
    print theFeedUrl
    req = requests.get(theFeedUrl)
    f = req.text
    decoded = json.loads(f)
    return decoded

next = "https://graph.facebook.com/%s?fields=comments.limit(100).fields(likes,message,from,like_count)" % post_id
x = 0
while x < 40:
    decoded = getmore(next)
    try:
        comments = decoded['comments']['data']
        next = decoded['comments']['paging']['next']

    except:
        comments = decoded['data']
        next = decoded['paging']['next']

    for d in comments:
        print '%s\t%s\t%s\t%s\t"%s"' % (d['created_time'],d['like_count'],d['from']['name'],d['from']['id'],d['message'])
    x = x + 1
#/usr/bin/env python
#编码:utf-8
"""
postgrabber.py
由伊恩于2012年9月24日创建。
版权所有(c)2012 uu MyCompanyName uuu。保留所有权利。
"""
导入系统
导入操作系统
导入ogp
导入配置
导入httplib
将simplejson导入为json
导入请求
getData=ogp.facebookquerys()
post_id=“145061248901557_381440708596942”
def getmore(下一步):
access\u token=getData.authenticate()
OFFEDURL=nexturl+“&”+访问令牌
印刷品
req=请求。获取(OFFEDURL)
f=请求文本
decoded=json.loads(f)
返回解码
下一个=”https://graph.facebook.com/%s?fields=comments.limit(100).字段(likes、message、from、like\u计数)“%post\u id
x=0
当x<40时:
解码=获取更多信息(下一步)
尝试:
注释=解码['comments']['data']
下一步=解码的['comments']['paging']['next']
除:
注释=已解码['data']
next=已解码['paging']['next']
对于评论中的d:
打印“%s\t%s\t%s\t%s\t”%s“%”(d[“创建时间”]、d[“类似计数”]、d[“来自”][“名称”]、d[“来自”][“id”]、d[“消息”])
x=x+1
我敢肯定,我得到了1000多条公众评论。这篇帖子总共有4780条评论,我想不太可能有3800条评论是私人的


还有其他人遇到过这种情况吗?我做错什么了吗?

我发现了问题所在。令人惊讶的是,问了一群其他人后,突然发现了掌纹

我有这个:

    theFeedUrl = nexturl + "&" + access_token
应该是:

    theFeedUrl = nexturl + "&access_token=" + access_token

愚蠢粗心的错误,由于某种原因,Facebook允许我请求前1000个,但没有正确的URL。

如果它与reddit类似,出于性能/缓存原因,你无法获取超过前1000个。不要这样认为-Facebook已经为这类事情设置了分页,你甚至可以一次抓取1000个或更多,或者批量处理请求。这是一个副本:那里的答案可能对你有帮助。谢谢-我试过了,但没有解决问题。不过,在探险家中我确实可以超过1000。不知道有什么区别。