我正在使用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");
非常感谢任何帮助。
感谢。
答案 0 :(得分: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();
}
答案 1 :(得分: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