Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram Business Discovery API Pagination Token not working?

I am trying to use Instagram Business Discovery API to get post statistics from a certain public page.

Take Bath and Body Works (https://www.instagram.com/bathandbodyworks) for example.

GET graph.facebook.com
   17895695668004550?fields=business_discovery.username(bathandbodyworks){followers_count,media_count,media{timestamp,like_count,comments_count}}

This will give me the following response:

{
"business_discovery": {
"followers_count": 3526159,
"media_count": 3536,
"media": {
  "data": [
    {
      "timestamp": "2018-05-16T20:00:54+0000",
      "like_count": 28925,
      "comments_count": 530,
      "id": "17917935010179826"
    },

    (24 posts data omitted...)

    "paging": {
    "cursors": {
      "after": "QVFIUlBNak5fNTc3eThl..." (a very long string)
    }
  }
}

Now, this only gives me the most recent 25 posts, which I believe is the limit per request set by Facebook.

What should I do if I want to load the next 25 posts?

In YouTube Data API there is also a limit per request of 50, but a "nextPageToken" is provided to load the next 50 post. I assume this is the same case here?

I also found in this Facebook API document that maybe I can add a cursor string like: &after=QVFIUlBNak5fNTc3eThl...,

but this doesn't work.

Any suggestions would be appreciated, thank you!

like image 868
Jacob C Avatar asked Oct 14 '25 07:10

Jacob C


1 Answers

The pagination with business_discovery is a bit different from Facebook pagination.

There's no next and previous url's.

You need to add, after cursor as this example:

https://graph.facebook.com/v2.12/xxxx?fields=business_discovery.username(jacqehoward){id,name,username,website,profile_picture_url,biography,followers_count,media_count,media.after(QVFIUlZA5aTR5NTE4Y24tNW90VGZAPTVBtb0NpOEFPTlNLeklmVTEtUDZAfVnE0YnBhUVNOQ3BDaktzNHJBTENhTmVYLUV2SGJPZAVAxZA09hQ2NhUGdnUGFjMTNn){id,caption,comments_count,like_count,media_type,media_url,owner,timestamp}}

Note:

media.after(after_cursor){media_fields}

And if you want to paginate through business_discovery to the end you must add after cursors until there's only response with previous cursor. This is the mark that you reached the first post.

like image 59
jordivador Avatar answered Oct 19 '25 13:10

jordivador