.net - 使用ResumableUploader将大型视频文件(mp4,130兆字节)上传到YouTube

标签 .net api c#-4.0 youtube google-api

我有以下代码

                            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将来的问题。

  • 下载Fiddler
  • 监视对YouTube执行的Web请求。
  • Youtube将返回描述性响应以及HTTP 400状态代码。
  • 描述性回答将为您提供答案。瞧!

  • 如果您按照上述步骤进行操作,然后在您的问题中添加YouTube回答,那么人们会更容易获得帮助。

    关于.net - 使用ResumableUploader将大型视频文件(mp4,130兆字节)上传到YouTube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21123092/

    相关文章:

    ruby - 在 Sinatra 中跟踪 "conversation"流

    c - 这个循环有问题吗?

    java - 用于查找域类别的 API

    .net - 如何正确使用BeginRead的 'state'参数?

    c# - 如何使用 .net 实现 SQL IN() 的等价物

    c# - FileSystemWatcher 锁定文件夹

    c# - 如何创建与资源管理器具有相同选项的上下文菜单

    c# - 与 Crystal Reports 中的公式相关的问题

    c# - 创建结果已经准备好的任务的正确方法

    c# - 更新 AD 用户信息