2013-02-06 69 views
1

我正在嘗試使用carrierwave發佈更新,以便使用carrierwave ...與媒體。twitter update_with_media和carrierwave

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,但它不起作用。

回答

1
require 'open-uri' 
Twitter.update_with_media("message", open(picture.picture_url.to_s) {|f| f.read }) 
4

只是爲其他

> Source

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
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 
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 
好處
相關問題