Created
July 4, 2013 17:27
-
-
Save ascot21/5929236 to your computer and use it in GitHub Desktop.
Download images from Instagram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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