YouTube C#API上传大型视频

时间:2013-08-24 01:32:05

标签: c# youtube-api

我正在尝试使用C#API将500 MB视频上传到YouTube。在最后一行,我收到一个参数null异常。什么是URI,这是第二个参数,应该是什么?这是我的代码:

[WebMethod]
public string InsertVideoToYouTube(FileStream fs, string filename, string title, string description, string userName, string password)
{
    Video newVideo = new Video();
    newVideo.Title = title;
    newVideo.Tags.Add(new MediaCategory("Sports", YouTubeNameTable.CategorySchema));
    newVideo.Description = description;
    newVideo.YouTubeEntry.Private = false;
    newVideo.YouTubeEntry.MediaSource = new MediaFileSource(fs, Path.GetFileName(filename), "video/x-ms-wmv");

    var youTubeAuthenticator = new ClientLoginAuthenticator("KenticoVideo",
                    ServiceNames.YouTube, new GDataCredentials(userName, password));
youTubeAuthenticator.DeveloperKey = "xxx";
    ResumableUploader uploader = new ResumableUploader(256);

    uploader.Insert(youTubeAuthenticator, new Uri("http://www.mysite.com"), fs, "video/x-ms-wmv", ""); // start upload
}

这是堆栈跟踪:

System.ArgumentNullException: Value cannot be null.
Parameter name: uriString
   at System.Uri..ctor(String uriString)
   at Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, String contentType, String slug, Int64 contentLength, String httpMethod)
   at Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, String contentType, String slug, Int64 contentLength)
   at Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, Uri resumableUploadUri, Stream payload, String contentType, String slug, AsyncData data)
   at Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, Uri resumableUploadUri, Stream payload, String contentType, String slug)
   at PreveaYTProxy.InsertVideoToYouTube(FileStream fs, String filename, String title, String description, String userName, String password) in c:\inetpub\wwwroot\Customers\imaginasium\PreveaYTProxy\App_Code\PreveaYTProxy.cs:line 57
   at _Default.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Customers\imaginasium\PreveaYTProxy\Default.aspx.cs:line 20
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

我使用的是正确的代码吗?我看了一下,但是找不到我需要的代码:

https://groups.google.com/forum/#!topic/gdata-dotnet-client-library/AWoPGB9_NzE

0 个答案:

没有答案