0

我在 Facebook 上发布了至少 4,000 条已确认的公众评论。但我不能得到超过 980 个。

每次,一旦我清除 900,我都会收到此错误:

Traceback (most recent call last):
    File "fb_pcf_temp.py", line 41, in <module>
    next = decoded['paging']['next']
KeyError: 'next'

我的代码是:

#!/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

我很肯定我已经收到了超过 1000 条公众评论。该帖子总共有 4780 条评论——我认为其中 3800 条不太可能被标记为私人评论。

有人遇到过这种情况么?我在做一些明显的错误吗?

4

1 回答 1

0

我发现了问题。令人惊讶的是,问一群其他人如何突然暴露了手掌。

我有这个:

    theFeedUrl = nexturl + "&" + access_token

它应该是:

    theFeedUrl = nexturl + "&access_token=" + access_token

愚蠢的粗心错误,由于某种原因,Facebook 让我请求前 1000 个不带正确 URL 的事实使情况更加复杂。

于 2012-11-02T14:08:38.843 回答