【问题标题】:Resumable YouTube Data API v3 uploads using Ruby使用 Ruby 的可恢复 YouTube 数据 API v3 上传
【发布时间】:2013-05-10 16:08:25
【问题描述】:

我目前正在使用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?

【问题讨论】:

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


    【解决方案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."
    

    这对我有用。

    【讨论】:

    • 即使我将其更改为显式执行videos_insert_response.resumable_upload.send_all(client),响应正文仍为空白并且上传成功完成,就像之前没有send_all 一样。尝试访问 videos_insert_response.data 会导致 ArgumentError:Content-Type not supported for parsing: text/html 异常。您用来测试的 body 是什么?
    • 其余代码与developers.google.com/youtube/v3/code_samples/ruby#upload_video相同 试试sudo gem update google-api-client?我正在使用 v0.6.3 进行测试。
    • 看起来这是问题所在,我们使用的是 v0.4.4。
    【解决方案2】:

    我正在使用 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."
    

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 2015-01-08
      • 1970-01-01
      相关资源
      最近更新 更多