使用Ruby恢复可恢复的YouTube Data API v3上传
发布时间:2020-12-17 02:04:34 所属栏目:百科 来源:网络整理
导读:我目前正在使用 google-api-ruby-client将视频上传到Youtube API V3,但我找不到获取由可恢复上传创建的Youtube ID的方法.我试图使用的代码是: media = Google::APIClient::UploadIO.new(file_path,'application/octet-stream')yt_response = @client.execut
我目前正在使用
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? 解决方法
合成
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." 这对我有用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |