我試圖上傳一個使用GData gem的YouTube視頻(我已經看到了youtube_g gem,但是如果可能的話我想要使用純GData),但是我一直收到這個錯誤:如何使用Ruby上傳YouTube上的視頻
'MyProject :: Google :: YouTube中的GData :: Client :: BadRequestError'應該將實際視頻上傳到YouTube(一旦出現,模擬此測試)' 請求錯誤400:在上傳請求中找不到文件。
我使用這個代碼:
def metadata
data = <<-EOF
<?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <media:group> <media:title type="plain">Bad Wedding Toast</media:title> <media:description type="plain"> I gave a bad toast at my friend's wedding. </media:description> <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category> <media:keywords>toast, wedding</media:keywords> </media:group> </entry> EOF end
@yt = GData::Client::YouTube.new @yt.clientlogin("name", "pass") @yt.developer_key = "myKey" url = "http://uploads.gdata.youtube.com/feeds/api/users/name/uploads" mime_type = "multipart/related" file_path = "sample_upload.mp4" @yt.post_file(url, file_path, mime_type, metadata)
什麼是上傳視頻到YouTube與紅寶石推薦/標準的方式,你有什麼方法?
更新
應用更改wrapped_entry
後,串它產生看起來是這樣的:
--END_OF_PART_59003 Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <media:group> <media:title type="plain">Bad Wedding Toast</media:title> <media:description type="plain"> I gave a bad toast at my friend's wedding. </media:description> <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category> <media:keywords>toast, wedding</media:keywords> </media:group> </entry>
--END_OF_PART_59003 Content-Type: multipart/related Content-Transfer-Encoding: binary
...和檢查請求和響應看起來是這樣的:
要求:
<GData::HTTP::Request:0x1b8bb44 @method=:post
@url="http://uploads.gdata.youtube.com/feeds/api/users/lancejpollard/uploads"
@body=#<GData::HTTP::MimeBody:0x1b8c738 @parts=[#<GData::HTTP::MimeBodyString:0x1b8c058
@bytes_read=0
@string="--END_OF_PART_30909\r\nContent-Type: application/atom+xml; charset=UTF-8\r\n\r\n
<?xml version=\"1.0\"?>\n<entry xmlns=\"http://www.w3.org/2005/Atom\"\n xmlns:media=\"http://search.yahoo.com/mrss/\"\n xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n <media:group>\n <media:title type=\"plain\">Bad Wedding Toast</media:title>\n <media:description type=\"plain\">\n I gave a bad toast at my friend's wedding.\n </media:description>\n <media:category scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">People</media:category>\n <media:keywords>toast wedding</media:keywords>\n </media:group>\n</entry>
\n\r\n--END_OF_PART_30909\r\nContent-Type: multipart/related\r\nContent-Transfer-Encoding: binary\r\n\r\n">
#<File:/Users/Lance/Documents/Development/git/thing/spec/fixtures/sample_upload.mp4>
#<GData::HTTP::MimeBodyString:0x1b8c044 @bytes_read=0
@string="\r\n--END_OF_PART_30909--">]
@current_part=0
@boundary="END_OF_PART_30909">
@headers={"Slug"=>"sample_upload.mp4"
"User-Agent"=>"GoogleDataRubyUtil-AnonymousApp"
"GData-Version"=>"2"
"X-GData-Key"=>"key=AI39si7jkhs_ECjF4unOQz8gpWGSKXgq0KJpm8wywkvBSw4s8oJd5p5vkpvURHBNh-hiYJtoKwQqSfot7KoCkeCE32rNcZqMxA"
"Content-Type"=>"multipart/related; boundary=\"END_OF_PART_30909\""
"MIME-Version"=>"1.0"}>
響應:
#<GData::HTTP::Response:0x1b897e0 @body="No file found in upload request." @headers={"cache-control"=>"no-cache no-store must-revalidate" "connection"=>"close" "expires"=>"Fri 01 Jan 1990 00:00:00 GMT" "content-type"=>"text/plain; charset=utf-8" "date"=>"Fri 11 Dec 2009 02:10:25 GMT" "server"=>"Upload Server Built on Nov 30 2009 13:21:18 (1259616078)" "x-xss-protection"=>"0" "content-length"=>"32" "pragma"=>"no-cache"} @status_code=400>
仍然沒有工作,我將不得不與這些變化更多的檢查出來。
還沒有得到它的工作,我希望這可以修復它!謝謝! – 2010-03-24 00:42:53