2014-01-08 144 views
0

我正在使用以下代碼將視頻上傳到YouTube。 它總是給出以下錯誤。將視頻上傳到YouTube時出錯

The remote server returned an error: (403) Forbidden. 

我的代碼是

 YouTubeRequestSettings settings; 
     YouTubeRequest request; 
     string devkey = YouTubeDeveloperKey; 
     string username = YoutubeUserName; 
     string password = YoutubePassword; 
     settings = new YouTubeRequestSettings("VideoEditor", devkey, username, password) { Timeout = -1 }; 
     request = new YouTubeRequest(settings); 

     Video newVideo = new Video(); 

     newVideo.Title = Title; 
     newVideo.Description = Description; 
     newVideo.Private = true; 
     newVideo.YouTubeEntry.Private = false; 

     newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/flv"); 
     Video createdVideo = request.Upload(newVideo); 

請你對這個錯誤

+0

你可以顯示返回的xml嗎? –

+0

如何獲得XML?它在線上發生錯誤Video createdVideo = request.Upload(newVideo); – las

+0

在該行設置一個斷點並「跳入」代碼。 –

回答

0

由於每Youtube API V2 documentation任何想法,錯誤403authorization error

很可能用戶名和密碼可能是錯誤的。

我的猜測:您是否在您的Google帳戶中啓用了兩步驗證? 如果是這樣,您必須使用application-specific password

+0

不,我沒有啓用兩步驗證,用戶名和密碼正確,我可以使用瀏覽器登錄到YouTube – las

+0

嘗試在'request = new YouTubeRequest(設置)'處設置斷點;'將鼠標懸停在'settings'上以查看它的價值,並確保用戶名和密碼是你所期待的。 –

+0

並請看看[這個問題](http://stackoverflow.com/questions/10759032/how-to-use-the-youtube-api-login-procedure-using-c)已經問過,並確認給自己你正在發送正確的憑證。並且按照[那個問題]中的答案(http://stackoverflow.com/questions/10759032/how-to-use-the-youtube-api-login-procedure-using-c)。 –

0

嘗試通過https://console.developers.google.com轉到您的YouTube應用程序,然後選擇您的應用程序轉到API和授權 - > API。 它將顯示多個可用API的列表,單擊Youtube Data API,然後單擊「啓用」。這將使您的應用程序可以使用此API,並且很可能會解決您的問題。