Home Articles

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

Asked
Viewed 506 times
4

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

  • 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."
    

    这对我有用 .

  • 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."
    

Related