我正在尝试使用carrierwave将来自heroku的更新发布到twitter ...与媒体。
http://rdoc.info/gems/twitter/Twitter/API/Tweets#update_with_media-instance_method
我可以在没有媒体的情况下做到这一点,但是当我尝试媒体时,我一直遇到问题。
Twitter.update_with_media("message", File.new(picture.picture_url.to_s))
我收到错误:
Errno::ENOENT (No such file or directory - https://amazonlinktopicture)
有什么想法吗?我也尝试使用File.open,但它没有用。
答案 0 :(得分:4)
只是为了其他人的利益
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
答案 1 :(得分:1)
require 'open-uri'
Twitter.update_with_media("message", open(picture.picture_url.to_s) {|f| f.read })
答案 2 :(得分:1)
begin
twitter_client = Twitter::REST::Client.new 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
twitter_client.update_with_media(message, open(picture.picture_url))
rescue Exception => exc
@message = exc.message
end
答案 3 :(得分:1)
begin
twitter_client = Twitter::REST::Client.new do |client|
client.consumer_key = config['consumer_key']
client.consumer_secret = config['consumer_secret']
client.oauth_token = config['oauth_token']
client.oauth_token_secret = config['oauth_token_secret']
end
twitter_client.update_with_media(message, open(picture.picture_url))
rescue Exception => exc
@message = exc.message
end