Facebook Graph API: Download all posts with likes and comments of those posts at the same time (paging)

1.9k views Asked by At

I am trying to download all the posts and the comments(and replies to comments) for that post in a public facebook page. Here is the code that I am using:

from facepy import GraphAPI
import json

page_id = "Google"
access_token = "access_token"

graph = GraphAPI(access_token)



data = graph.get(page_id + "/feed", page=True, retry=3,    limit=100,fields='message,likes')


i = 0
for p in data:
    print 'Downloading posts', i
    with open('facepydata/content%i.json' % i, 'w') as outfile:
       json.dump(p, outfile, indent = 4)
    i += 1

First of all (1) this code is giving me this exception:
facepy.exceptions.FacebookError: [1] Please reduce the amount of data you're asking for, then retry your request
How should I solve this problem?
Second: (2)How can I get all the likes,comments and replies at the same time of getting the posts (paging is also required in likes,comments and replies to get all of them). page=True not working for these fields.

Thank you!

1

There are 1 answers

0
ratchet On

Facebooks Graph API has rate limiting. I believe @Klaus-D is correct that the error it is clear the request should have a lower limit parameter set, in which you can then page through the results of.

I would try limit=10, and then page through with your loop as you have it.