Instagram Basic Display API Pagination

↘锁芯ラ 提交于 2020-05-28 06:49:19

问题


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


回答1:


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}



来源:https://stackoverflow.com/questions/59814442/instagram-basic-display-api-pagination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!