How do I get the next page of results using the Instagram gem?
The documentation for the API itself says there is a pagination
hash passed in with each result (see here: http://instagram.com/developer/endpoints/). How do I access that with the gem?
Got it. I don't think the pagination
hash that Instagram passes back is accessible, but you can pass in a max_id
option when querying, to get the next set of older pictures.
@results = Instagram.user_recent_media(some_user_id, {access_token: token, count: 10, max_id: 197679035065553721})
By passing in max_id
(the id of a photo), it will return all results older than that. So grab the id of the oldest photo from the first query, and pass it in to get the next page.
Note: when you get the results, the ids of pictures are in the form: 197679035065553721_someuserid
. You have to parse out the first bit before the underscore, and pass that in as max_id
.
Instagram.tag_recent_media(params[:q]).pagination
run that code and you will see the pagination attributes.
I have looked into this for a project of my own and eventually found that you can get the client to give you the pagination info by setting no_response_wrapper to true when creating the client:
client = Instagram.client(:access_token => accesstoken,
:no_response_wrapper => true)
This makes it so you can use .pagination on the response as Yigit C. Bacakoglu suggested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With