1

我正在尝试使用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 ,但它没有用。

4

4 回答 4

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
于 2013-12-02T07:46:30.853 回答
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
于 2014-08-21T12:34:52.467 回答
1
require 'open-uri'
Twitter.update_with_media("message", open(picture.picture_url.to_s) {|f| f.read })
于 2013-02-06T21:47:27.540 回答
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
于 2014-06-06T13:44:48.297 回答