Paginate并收集来自Facebook的帖子和评论(Python,Json)

时间:2015-08-07 08:41:00

标签: python json facebook pagination

我无法解决如何为我的项目从Facebook分页和收集数据的问题。我知道我必须制作一个循环才能收集它,但它似乎没有工作,我无法解决错误。这是我的代码:

import requests
import facebook
import json

def some_action(post):
    print posts['data']
    print post['created_time']

#Token
access_token = 'INSERT ACCESS TOKEN'
user = 'INSERT NAME'

#Posts
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'posts')

x=0
while x < 500:
    y=0
    while y < 500:
        try:
            posts = requests.get(posts['paging']['previous']).json()


            y = y+1

            while True:
                posts = requests.get(posts['paging']['next']).json()
                with open('aa10.txt', 'a') as textfile:
                    json.dump(posts, textfile)
        except KeyError:
            break
x = x+1

对于我需要改变什么的任何想法?我知道我需要编辑&#34;分页&#34;字符串具体地说。这里的问题是分页和限制= 25。有谁知道我怎么能稍微增加这个?

0 个答案:

没有答案