我尝试使用youtube data api将本地视频文件上传到我的YouTube帐户。
示例:https://github.com/youtube/api-samples/blob/master/ruby/upload_video.rb
呼叫:
$ ruby upload_video.rb --file video.mp4
我收到错误消息:
/Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:326:in `syswrite': Broken pipe (Errno::EPIPE)
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:326:in `do_write'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:344:in `write'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:202:in `copy_stream'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:202:in `send_request_with_body_stream'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:132:in `exec'
...
from upload_video.rb:73:in `main'
from upload_video.rb:91:in `<main>'
upload_video.rb(第73行):
videos_insert_response = client.execute!(
:api_method => youtube.videos.insert,
:body_object => body,
:media => Google::APIClient::UploadIO.new(opts[:file], 'video/*'),
:parameters => {
:uploadType => 'resumable',
:part => body.keys.join(',')
}
)
答案 0 :(得分:10)
google-api-client使用法拉第宝石,默认的http适配器是Net :: HTTP。它似乎无法正常工作。因此我们需要将其切换为其他内容。我将其更改为httpclient,现在工作正常。 只需在whatever.rb文件的开头某处添加此行(在需要google的库后):
Faraday.default_adapter = :httpclient
可在此处找到支持的http适配器的完整列表:https://github.com/lostisland/faraday#faraday