Fetching all user’s pictures with the Instagram gem

I’d like to fetch all my pictures using the instagram gem (https://github.com/Instagram/instagram-ruby-gem) but I’m not able to find out how.

This is what I’m trying so far:

client = Instagram.client(access_token: token)
client.user_recent_media.each do |media|
    puts media.images.thumbnail.url
end

It apparently works (those are my Instagram images) but I’m not able to fetch all of them or to select in any way which content I want from Instagram.

For example I see that the method user_recent_media accepts a “count” attribute that should let me use some sort of pagination:

(from https://github.com/Instagram/instagram-ruby-gem/blob/master/lib/instagram/client/users.rb#L150)
@option options [Integer] :count (nil) Limits the number of results returned per page

Unfortunately I don’t get how this paginations is supposed to work. If for example I request 1000 media elements (just to say all of them) it doesn’t work and returns way less elements, at that point I’m stuck because I have no idea how to requeste page 2

Has anyone used the Instagram gem for something like this? Any help is greatly appreciated


Source: ruby

Leave a Reply