1

我正在使用 Async ResumableUpload 将视频上传到 YouTube,但是我无法检索成功上传视频的 VideoID。这对于单个 Sync 上传非常容易,但我一直无法找到 Async 的任何示例。

这是代码:

        var mResumableUploader = new ResumableUploader(chunkSize);
        mResumableUploader.AsyncOperationCompleted += MResumableUploaderAsyncOperationCompleted;
        mResumableUploader.AsyncOperationProgress += MResumableUploaderAsyncOperationProgress;

        var youTubeAuthenticator = new ClientLoginAuthenticator(appName, ServiceNames.YouTube, uName, passWord);
        youTubeAuthenticator.DeveloperKey = devKey;

        newVideo = new Video();

        newVideo.Title = "video";
        newVideo.Tags.Add(new MediaCategory("Entertainment", YouTubeNameTable.CategorySchema));
        newVideo.Keywords = "video";
        newVideo.Description = "video";
        newVideo.YouTubeEntry.Private = false;
        newVideo.YouTubeEntry.MediaSource = new MediaFileSource(fileName, fileContType);

        var link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads");
        link.Rel = ResumableUploader.CreateMediaRelation;
        newVideo.YouTubeEntry.Links.Add(link);

        Console.WriteLine("Starting upload: ");
        mResumableUploader.InsertAsync(youTubeAuthenticator, newVideo.YouTubeEntry, "inserter");

任何帮助都感激不尽。

谢谢。

4

2 回答 2

2

如谷歌数据提供的示例所示,您可以在上传过程完成后解析视频。问候

        ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(ru_AsyncOperationCompleted);

void ru_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
        {

            //upload complete
            YouTubeRequestSettings ytSettings = new YouTubeRequestSettings("myApp", googleDevKey, ytUsername, ytPassword);
            Video v = ytRequest.ParseVideo(e.ResponseStream);
            string videoId = v.VideoId;
            string watchPage = v.WatchPage.ToString();

        }
于 2013-01-22T20:25:31.090 回答
1

使用 YouTube API v3,您无需使用 ResumableUploader。您只需向 VideoInsertRequest ResponseReceived 添加一个委托:

var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Default Video Title";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
var filePath = @"REPLACE_ME.mp4"; // Replace with path to actual movie file.

using (var fileStream = new FileStream(filePath, FileMode.Open))
{
  var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
  videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
  await videosInsertRequest.UploadAsync();
}

void videosInsertRequest_ResponseReceived(Video video)
{
  Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
}

完整的代码在这里:https ://developers.google.com/youtube/v3/code_samples/dotnet#upload_a_video

于 2017-02-28T16:43:41.427 回答