问题
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