只为他人的利益
> 来源
require 'twitter'
require 'open-uri'
config = YAML.load_file('twitter.yml')
Twitter.configure do |c|
c.consumer_key = config['consumer_key']
c.consumer_secret = config['consumer_secret']
c.oauth_token = config['oauth_token']
c.oauth_token_secret = config['oauth_token_secret']
end
# Tempfile
begin
uri = URI.parse('https://dev.twitter.com/sites/default/files/images_terms/tweet-display-guidelines-20110405.png')
media = uri.open
media.instance_eval("def original_filename; '#{File.basename(uri.path)}'; end")
p Twitter.update_with_media(Time.now.to_s, media)
rescue => e
p e
end
# StringIO
begin
uri = URI.parse('http://a3.twimg.com/a/1315421129/images/logos/twitter_newbird_blue.png')
media = uri.open
media.instance_eval("def original_filename; '#{File.basename(uri.path)}'; end")
p Twitter.update_with_media(Time.now.to_s, media)
rescue => e
p e
end