【问题标题】:Uploading large video file(mp4, 130 megabyte) to YouTube with ResumableUploader使用 ResumableUploader 将大型视频文件(mp4,130 兆字节)上传到 YouTube
【发布时间】:2014-02-03 01:49:37
【问题描述】:

我有以下代码

                            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>

【问题讨论】:

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


    【解决方案1】:

    我有一个建议可以帮助您解决这个问题以及 Youtube API 的未来问题。

    1. 下载Fiddler
    2. 监控正在向 Youtube 发出的网络请求。
    3. Youtube 将返回一个描述性响应以及 HTTP 400 状态代码。
    4. 描述性响应将为您提供答案。瞧!

    如果您按照上述步骤并将 Youtube 回复放在您的问题中,人们会更容易为您提供帮助。

    【讨论】:

    猜你喜欢
    • 2014-01-14
    • 2019-10-26
    • 1970-01-01
    • 2012-04-07
    • 2016-01-27
    • 2013-09-19
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    相关资源
    最近更新 更多