使用Ruby恢复可恢复的YouTube Data API v3上传

时间:2013-05-15 22:25:48

标签: ruby youtube-api google-api-ruby-client

我目前正在使用google-api-ruby-client将视频上传到Youtube API V3,但我找不到获取可恢复上传所创建的Youtube ID的方法。我试图使用的代码是:

media = Google::APIClient::UploadIO.new(file_path, 'application/octet-stream')
yt_response = @client.execute!({
  :api_method => @youtube.videos.insert,
  :parameters => {
    :part => 'snippet,status',
    'uploadType' => 'resumable'
  },
  :body_object => file_details,
  :media => media
})
return JSON.parse(yt_response.response.body)

但遗憾的是,对于可恢复上传,yt_response.response.body为空。如果我将'uploadType'更改为'multipart',则body是包含Youtube ID的JSON blob。可恢复上传的响应仅是具有空体的上载的可恢复会话URI。如何从该URI转到我刚创建的Youtube ID?

2 个答案:

答案 0 :(得分:1)

How to engage a Resumable upload to Google Drive using google-api-ruby client?existing multipart upload sample合成信息

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(',')
  }
)
videos_insert_response.resumable_upload.send_all(client)
puts "'#{videos_insert_response.data.snippet.title}' (video id: #{videos_insert_response.data.id}) was successfully uploaded."

这对我有用。

答案 1 :(得分:0)

我正在使用0.7.1版本的API进行可恢复的上传,我不得不通过这个来获取ID ...

result = videos_insert_response.resumable_upload.send_all(client)
video = JSON.parse(result.response.body)

puts "Video id '#{video['id']}' was successfully uploaded."