我目前正在使用 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。可恢复上传的响应只是带有空主体的上传的可恢复 session URI。我如何从该 URI 进入我刚刚创建的 Youtube ID?
最佳答案
正在综合来自 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."
这对我有用。
关于ruby - 使用 Ruby 的可恢复 YouTube 数据 API v3 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16576019/