我有以下代码
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);
Evertything似乎工作正常,直到最后一行
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>
答案 0 :(得分:0)
我向您提出建议,这将有助于您解决此问题以及Youtube API的未来问题。
如果您按照上述步骤并在问题中添加Youtube回复,那么人们会更容易帮助您。