English 中文(简体)
试图通过Sinatra的POST将图像上载到Twitter的问题
原标题:Problems attempting to upload image to Twitter via POST in Sinatra

I m using Sinatra 1.2.6 in Duncan 1.8.7,我有像Twitter客户那样写Im的文章。 我正在使用。 John Nunemaker撰写的Twitgem版本1.7.2。 http://sequel.rubyforge.org/“rel=“nofollow”

总的来说,事情是巨大的。 我的奥乌特工作顺序良好,通过奥乌特进程的任何用户都可以把茨韦特寄给我的申请。

然而,在我生活中,我无法利用最新情况——与媒体一道——获得媒体上的有效载荷。 我试图上载一个多部分的星流图像档案,保持记忆,然后交给Twitter。

post  /file_upload  do
  user_name = params[:user]
  if params[:action] == "FILE-UPLOAD"
    unless params[:name].match(/.jpg|png|jpeg/).nil?

          #Assume these 3 lines work, and properly authorize to Twitter
      current_user = User[:user_name => user_name, :current_account => "1"]
      client = current_user.authorize_to_twitter #Handles the Oauth keys/process
          client.update("Text status updates work properly") 

          #Something incorrect is happening in the next two lines. 
          #I m either handling the file upload wrong, or posting wrong to Twitter
      datafile = params[:file]
      client.update_with_media("File upload from Skype: ", datafile)
      return "File uploaded ok"
    end
  end
end

然而,在我尝试的时候,我忘记:

Twitter::Unauthorized - POST https://upload.twitter.com/1/statuses/update_with_media.json: 401: Could not authenticate with OAuth.

它说出造成这一错误的行文是客户,更新日期——直线。

我正在尝试使用,但我不知道Im使用它是否不正确。 如果我不需要使用它,我就得了,但我现在就 st了。 该法典之外唯一使用该法典的事物是我的法典顶部:

require  rack/raw_upload 
use Rack::RawUpload

在这方面的任何帮助都将受到广泛赞赏。 我也用Tempfile.new()对我进行了尝试,但这种说法似乎在很大程度上起到了帮助作用,我或正在发现401或403个错误。 我对Ruby说了相当新的话,以便尽可能明确地说明所需变化,这确实是有益的。

我要指出,如果有可能,我想避免将档案列入档案系统。 我真的只是穿过上载,在我的设想下,我永远不需要再接手。 最好是在网上保存档案。

问题回答

You need to check how your library HTTP headers are setup and logically connected to the POST method you have written here. The thing is that for upload_with_media, twitter api in this gem version requires you to use http://upload.twitter.com upload endpoint instead of the default api endpoint. The gem may be forcing the api site so while the OAuth based status update works fine, it crashes when you try it with an image. You will need to check the gem documentation to figure out how to force the upload twitter site into the HTTP headers for this method.

或者,考虑更新最新目录。 这是我从查询的。

Twitter:API#update_with_media methods nomore use thetom upload.twitter.com endpoint, so media_endpoint formation has been addressed. 同样,Twitter:API#search方法不再使用习俗搜索方法。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签