视频上传后,如何使用 C# .NET 的 API 检查其处理状态?答案应该在Google.Apis.Youtube.v3.Data.VideoProcessingDetails中,但是该对象究竟应该如何实例化呢?以下代码引发 System.Net.Http.HttpRequestException:
video.ProcessingDetails = new VideoProcessingDetails();
上面的代码在以下上下文中使用:
UserCredential credential;
using (FileStream stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None,
new FileDataStore("YouTube.Auth.Store")).Result;
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = Title;
video.Snippet.Description = Description;
video.Snippet.Tags = Tags;
video.ProcessingDetails = new VideoProcessingDetails(); // Here it throws an exception
video.Snippet.CategoryId = CategotyId;
video.Status = new VideoStatus();
video.Status.PrivacyStatus = PrivacyStatus;
var filePath = FilePath;
这个想法是,一旦视频上传,循环检查视频是否仍在处理,并在处理完成后对其执行其他操作。
更新:我发现如果在上传视频后实例化对象(例如,在私有静态 void videosInsertRequest_ResponseReceived()方法中),异常就消失了,但是一旦我尝试访问视频。ProcessingDetails.ProcessingProgress.TimeLeftMs.Value,它说该值为空。
谢谢。