sns-sdks / python-facebook

A simple Python wrapper for facebook graph api :sparkles: :cake: :sparkles: .
https://sns-sdks.github.io/python-facebook/
328 stars 86 forks source link

Is 'paging' already implemented? #179

Closed P8H closed 2 years ago

P8H commented 2 years ago

Hi, I am using the FacebookApi and want to download all posts from my facebook page. I see, that the returning FeedResponse doesn't contains every post but instead includes a paging attribute. Question: How to retrieve all posts?

My code so far:

FacebookApi(app_id="", app_secret="", access_token=token)
rs = fb.page.get_posts(page_id, since=1630582537)
rs.paging

Thanks for help

MerleLiuKun commented 2 years ago

If you use fb.page.get_posts, paging is inside,

You want get all posts, You can use follows:

FacebookApi(app_id="", app_secret="", access_token=token)
rs = fb.page.get_posts(page_id, count=None, limit=100)

But, this may have some errors unexpected if page have too many posts. So you can get it month by month.

FacebookApi(app_id="", app_secret="", access_token=token)
rs_p1 = fb.page.get_posts(page_id, count=None, limit=100, since='2021-10-01', until='2021-11-01')
rs_p2 = fb.page.get_posts(page_id, count=None, limit=100, since='2021-11-01', until='2021-12-01')

BTW, since and until can only in six month.

Or, you can use base api GraphAPI and use method get_connection to do paging by hand.

P8H commented 2 years ago

Thank you very much, this helps a lot