Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram Basic Display API Pagination

Is there anyway to use paging for the media results obtained using the Instagram Basic Display API? I've read the following documentations but they don't have any examples for using pagination:

  • https://developers.facebook.com/docs/instagram-basic-display-api/reference/media/children
  • https://developers.facebook.com/docs/graph-api/using-graph-api#paging

I would like to limit the media returned in the response e.g. media 1-15 for the first call, then get the next set e.g. 16-30 in the next call.

TIA

like image 590
CDS Avatar asked Oct 24 '25 22:10

CDS


1 Answers

Found an answer by playing around with the pagination parameters from this documentation: https://developers.facebook.com/docs/graph-api/using-graph-api#paging

Currently, the Basic Display API returns the most recent 20 media by default. If you want to return more or less than this, use the following url:

https://graph.instagram.com/{user-id}/media?fields={media-fields-you-want-to-return}&access_token={access-token}&limit={number-of-media-you-want-to-return}

To do pagination, you need to have a "next" endpoint to call. To try this out, limit your first call to less than the number of media that you have. You should get 3 endpoints for pagination:

    "paging": {
              "cursors": {
                       "before": "abc",
                       "after": "def"
               },
              "next": "ghi"
    }

Now add your next endpoint to the original url above: https://graph.instagram.com/{user-id}/media?fields={media-fields-you-want-to-return}&access_token={access-token}&limit={number-of-media-you-want-to-return}&next={next-endpoint}

like image 190
CDS Avatar answered Oct 27 '25 00:10

CDS