Fetch the latest pictures posted by a twitter user
$ gem install twitter rest-client
$ irb
(or pry
, that's even better :-)
require 'twitter'
require 'restclient'
t = Twitter::Client.new(:consumer_key => 'YOUR_APP_KEY', :consumer_secret => 'YOUR_APP_SECRET', :oauth_token => 'YOUR_AUTH_TOKEN', :oauth_token_secret => 'YOUR_AUTH_SECRET')
photos = t.user_timeline(:screen_name => 'amedeo').map {|t| t.media.map(&:media_url) if t.media.size > 0}.compact.flatten
photos.each {|uri| print "Fetching #{uri}:large ..."; File.open(File.basename(uri), 'w+') { |f| f.write RestClient.get([uri, 'large'].join(':')) }; puts 'done' }
Find your .jpg
in the current working directory. :-)
Written by Marcello Barnaba
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#