Skip to content

Instantly share code, notes, and snippets.

@ascot21
Created July 4, 2013 17:27
Show Gist options
  • Save ascot21/5929236 to your computer and use it in GitHub Desktop.
Save ascot21/5929236 to your computer and use it in GitHub Desktop.
Download images from Instagram
require "restclient"
require "json"
media_url = "https://api.instagram.com/v1/tags/scottisla/media/recent?access_token=ACCESS_TOKEN"
urls = []
while media_url != nil
response = RestClient.get(media_url)
json = JSON.parse(response)
media_url = json["pagination"]["next_url"]
json["data"].each do |item|
urls << item["images"]["standard_resolution"]["url"]
end
# don't slam instagram's api
sleep 0.2
end
urls.each_with_index do |url, idx|
image = RestClient.get(url)
path = Dir.pwd + "/#{idx}.jpg"
File.open(path, 'w') {|f| f.write(image) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment