Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram gem: how to get next page of results?

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?

like image 385
bevanb Avatar asked May 26 '12 09:05

bevanb


3 Answers

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.

like image 156
bevanb Avatar answered Nov 20 '22 12:11

bevanb


Instagram.tag_recent_media(params[:q]).pagination

run that code and you will see the pagination attributes.

like image 26
yigitbacakoglu Avatar answered Nov 20 '22 14:11

yigitbacakoglu


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.

like image 1
Andrey Kurenkov Avatar answered Nov 20 '22 13:11

Andrey Kurenkov