我有以下代码:
var newVideo = new Video
{
Title = Path.GetFileNameWithoutExtension(file),
Keywords = keywordstring,
Description = "Some Description"
};
newVideo.Tags.Add(new MediaCategory(projectSettings.Category.ToString(), YouTubeNameTable.CategorySchema));
newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(file, "video/quicktime");
AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + Credentials.UserName.Split('@')[0] + "/uploads");
link.Rel = ResumableUploader.CreateMediaRelation;
newVideo.YouTubeEntry.Links.Add(link);
ResumableUploader ru = new ResumableUploader(10);
GDataCredentials credentials = new GDataCredentials(Credentials.UserName, Credentials.Pass);
Authenticator youTubeAuthenticator = new ClientLoginAuthenticator("OnlineVideoDrive",ServiceNames.YouTube, credentials);
youTubeAuthenticator.DeveloperKey = "AIzaSyCdvck_1yrovHGusir2Ddw8KlYvl7rj2LQ";
ru.Insert(youTubeAuthenticator, newVideo.YouTubeEntry);
直到最后一行,一切似乎都工作正常
ru.Insert(youTubeAuthenticator, newVideo.YouTubeEntry);
线路抛出
WebException
:
System.Net.WebException ist aufgetreten.
HResult=-2146233079
Message=Der Remoteserver hat einen Fehler zurückgegeben: (400) Ungültige Anforderung.
Source=System
StackTrace:
bei System.Net.HttpWebRequest.GetResponse()
bei Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, AbstractEntry entry, String httpMethod)
bei Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, AbstractEntry entry)
bei Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, AbstractEntry payload, AsyncData data)
bei Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, AbstractEntry payload)
bei LetsPlayHelper.Form1.youtubeBackgroundWorker_DoWork(Object sender, DoWorkEventArgs e) in f:\Project\Form1.cs:Zeile 348.
InnerException:
我已经尝试使用 YouTubeRequest 类直接上传。小视频不是问题,但较大的视频会导致请求中止。
编辑:ex.Response.StatusCode 和 StatusDescription 是“BadRequest”
编辑2:整个上传代码在BackGroundWorker中运行
编辑3:我也尝试了YouTubeUploader示例,但出现了同样的错误(https://code.google.com/p/google-gdata/wiki/YouTubeUploader)
我用Fiddler抓取了回复
发现:
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>InvalidRequestUriException</code><internalReason>Exception message unavailable</internalReason></error></errors>
我有一个建议可以帮助您解决这个问题以及 Youtube API 的未来问题。
如果您按照上述步骤操作并将 Youtube 回复放入您的问题中,人们会更容易为您提供帮助。