上傳視頻後,如何使用C#.NET API檢查其處理狀態? 答案應該在Google.Apis.Youtube.v3.Data.VideoProcessingDetails中,但該對象究竟應該如何實例化?下面的代碼拋出一個System.Net.Http.HttpRequestException:YouTube API v3檢查視頻處理狀態
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;
的想法中,一旦視頻上傳,檢查在如果視頻仍在處理中,則循環,並在處理完成後對其執行其他操作。
更新:我想通了,如果視頻被上傳後的對象實例化(即在私有靜態無效videosInsertRequest_ResponseReceived()方法,例如),異常消失了,但一旦我嘗試訪問視頻。 ProcessingDetails.ProcessingProgress.TimeLeftMs.Value,它表示該值爲空。
謝謝。