2013-06-03 23 views
1

這是我的錯誤:淨YouTube的API 2.0 - 一致錯誤上傳 - 「請求已被取消」

An unhandled exception of type 'System.Net.WebException' occurred in Google.GData.Client.dll 

Additional information: The request was aborted: The request was canceled. 

我修整我的代碼到我使用的是什麼樣的基本版本:

 YouTubeRequestSettings settings; 
     YouTubeRequest request; 
     string devkey = "AI39si7VBlJSkNcHUWZdk5OPYa8IXZhVo-ak7KRtFYlfkCdt767P6oxPgoWcMXMfUCLL6-Ot3G-NmLe_cIlCWQDRq2FQl3F0aQ"; 
     string username = Username.Text; 
     string password = Password.Text; 
     Upload.Text = "Authenticating..."; 
     settings = new YouTubeRequestSettings("Music to YouTube", devkey, username, password) { Timeout = -1 }; 
     request = new YouTubeRequest(settings); 

     Video newVideo = new Video(); 

     newVideo.Title = Title.Text; 
     newVideo.Description = Description.Text; 
     newVideo.Keywords = Keywords.Text; 
     newVideo.Tags.Add(new MediaCategory("Music", YouTubeNameTable.CategorySchema)); 

     if (Privacy.Text == "Public") 
      newVideo.YouTubeEntry.Private = false; 
     else if (Privacy.Text == "Unlisted") 
      newVideo.YouTubeEntry.AccessControls.Add(new YtAccessControl("list", "denied")); 
     else if (Privacy.Text == "Private") 
      newVideo.YouTubeEntry.Private = true; 

     string fileMusic = "audio"; 
     string fileImage = "image"; 
     string fileTimeName = (DateTime.Now.Ticks/10000).ToString() + ".avi"; 

     File.Copy(MusicPath.Text, Environment.CurrentDirectory + "\\" + fileMusic, true); 
     File.Copy(ImagePath.Text, Environment.CurrentDirectory + "\\" + fileImage, true); 

     Upload.Text = "Mixing Music and Image..."; 
     var mix = Process.Start("ffmpeg.exe", "-loop 1 -r 1 -i " + fileImage + " -i " + fileMusic + " -shortest -vcodec mpeg4 -qscale:v 1 -acodec pcm_alaw -vf scale=\"'iw*max(1280/iw\\,720/ih)':'ih*max(1280/iw\\,720/ih)'\" " + fileTimeName); 

     File.Delete(fileMusic); 
     File.Delete(fileImage); 

     Upload.Text = "Uploading..."; 

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

     Upload.Text = "Uploaded!"; 
     File.Delete(fileTimeName); 

它在最近的上傳請求上失敗了,我找不到原因。上傳的最終文件由FFmpeg生成,並且我已經對其進行了徹底的測試,因此上傳的文件無需擔心,即使尺寸最多也只有30-40mb。

Timeout設置爲-1,所以理論上永遠不會觸發。我唯一可能猜到的是驗證失敗。

如果任何人有任何經驗,我會非常感謝幫助,因爲這讓我瘋狂。

+0

API如何上傳文件?這可能是因爲你需要禁用KeepAlive或者在某處設置MaxRequestLength .. –

回答

0

添加以下代碼行,它將解決您的問題。 ((GDataRequestFactory)request.Service.RequestFactory).Timeout = 9999999; ((GDataRequestFactory)request.Service.RequestFactory).KeepAlive = false;

相關問題