0
我有一個Facebook發佈至少4,000確認的公共意見。但我無法獲得超過980個。無法分頁通過API過去1000個Facebook評論
每次,當我清理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條被標記爲私有。
有沒有其他人遇到過這個?我做了什麼明顯的錯誤?
如果它與reddit很相似,那麼出於性能/緩存的原因,您無法抓住前1000個。 – ninMonkey
不要這麼想 - Facebook爲此類事物設置了分頁,並且您甚至可以一次抓取1000個或更多,或批量處理請求。 – user1066609
這是[facebook圖形API - 評論限於999]的副本(http://stackoverflow.com/questions/11756935/facebook-graph-api-comments-limited-to-999):答案可能會幫助你。 –