I'm creating a React Native app that calls the Instragram API to get the latest posts from a specific user. I use the pagination to get 6 posts every reload. I understand that when you call this:
https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN&count=COUNT
If given anything 20 or over for COUNT
will default to the maximum results of 20. For my case, I only request for 6 while giving it the last id
of the oldest dated post from the previous pagination call as the MAX_ID
.
All of this works fine until I start getting trying to get anything past the 20th most recent post. So, for example, here is the network results I get:
users/self/media/recent/?access_token=ACCESS-TOKEN&count=6 => {
data: {
[ ..., id: "12345"] // length of 6
},
pagination: {
next_max_id: "12345"
}
}
users/self/media/recent/?access_token=ACCESS-TOKEN&count=6&MAX_ID=12345 => {
data: {
[ ..., id: "67890"] // length of 6
},
pagination: {
next_max_id: "67890"
}
}
users/self/media/recent/?access_token=ACCESS-TOKEN&count=6&MAX_ID=67890 => {
data: {
[ ..., id: "34567"] // length of 6
},
pagination: {
next_max_id: "34567"
}
}
users/self/media/recent/?access_token=ACCESS-TOKEN&count=6&MAX_ID=34567 => {
data: {
[ ..., id: "89012"] // length of 2
},
pagination: {
next_max_id: "89012"
}
}
users/self/media/recent/?access_token=ACCESS-TOKEN&count=6&MAX_ID=89012 => {
data: {
[ ] // length of 0
},
pagination: { } // this is an empty object
}
All the requests (except the last two) are correct and give me valid data for me to use in my app.
Unless I'm misunderstanding how the API works, those last two requests should have given me 6 posts in the data response each, but instead, it gave me 2 and 0 respectively.
What am I doing wrong? How can I get this to properly paginate and consistently keep getting the next 6 posts?
Thanks!
If you are in Sandbox mode (which it sounds like you are), you will only be allowed to get the 20 most recent posts, even if you give it the pagination.