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
Below is functioning code from an old app that imports users (I just ran it with the 1.1.5 Instagram Gem and it still works), which also uses the cursor. You should be able to change a few variables and lines and be on your way:
def import_followers
response = user.client.user_follows
followers = [].concat(response)
next_cursor = response.pagination[:next_cursor]
while !(next_cursor.to_s.empty?) do
response = Instagram.user_follows(uid, {:cursor => next_cursor})
next_cursor = response.pagination[:next_cursor]
followers.concat(response)
end
return followers
end