2013-09-28 37 views
2

我很累,三天沒有睡覺,並且Im卡在1件東西, 這個youtube上傳的東西。Youtube API:恢復上傳*需要用戶認證*

這個非常簡單的POST過程總是會導致:「用戶身份驗證要求」

這是林爭相模仿:

POST /resumable/feeds/api/users/default/uploads HTTP/1.1 
Host: uploads.gdata.youtube.com 
Authorization: Bearer ACCESS_TOKEN 
GData-Version: 2 
X-GData-Key: key=adf15ee97731bca89da876c...a8dc 
Content-Length: 0 
Slug: my_file.mp4 

到目前爲止,這是香港專業教育學院做了什麼:

#!/usr/bin/perl 

use 5.010; 
use strict; 
use warnings; 
use LWP::Simple; 


    my $r = LWP::UserAgent->new()->post(
    "https://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads", 
     Content_Type => "application/atom+xml; charset=UTF-8", 
     [ 
     'POST /resumable/feeds/api/users/default/uploads HTTP/1.1', 
      Host   => "uploads.gdata.youtube.com", 
      'Authentication' => "Bearer xxxxxx", 
      'GData-Version' => "2", 
      'X-GData-Key' => "key=xxxxx", 
      Content_Length => "0", 
      'Slug' => "C:/YouTube.wmv", 
     ] 
    ); 

    say $r->content; 

我試過每個認證,Oath2,clientLogin, 我可以登錄並獲取access_token,問題是我c上傳,

我喜歡perl,我討厭沒有使用perl的youtube支持庫(這裏有,但是它的極其過時和直接的上傳功能沒有明確記錄,或者根本沒有) 請幫助我,我非常需要這個,我真的很困難,我不知道問題是出在我身上還是youtube的。

感謝您花時間閱讀本文,非常感謝。

+2

您確定您的驗證令牌有效嗎?也就是說,除了上傳工作外,還有其他方法嗎?另外,沒有用於Perl的youtube庫,因爲沒有人關心編寫和發佈Perl庫。上傳你在github上工作的任何東西,然後就可以運行你的代碼,查看出了什麼問題並將其解決。 – JackTheRandom

回答

1

對我來說,就像你對post()的呼叫使用了錯誤的語法。

documentation是真不明白,但我想你想是這樣的:

my $r = LWP::UserAgent->new()->post(
    'https://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads', 
    Content_Type => "application/atom+xml; charset=UTF-8", 
    [ 
     Host   => "uploads.gdata.youtube.com", 
     'Authentication' => "Bearer xxxxxx", 
     'GData-Version' => "2", 
     'X-GData-Key' => "key=xxxxx", 
     Content_Length => "0", 
     'Slug'   => "C:/YouTube.wmv", 
    ] 
); 

你並不需要一個線,明確要求POST()post()方法可以做到這一點。