7

嗯,我可以在Youtube上上傳視頻,但是我沒有找到方法或相關代碼從YouTube上刪除視頻/視頻。如何使用youtube v3 api和C刪除YouTube上的視頻#

這是我的代碼,我試圖刪除youtube視頻。

private async Task Run() 
    { 
     UserCredential credential; 
     using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) 
     { 
     credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
      GoogleClientSecrets.Load(stream).Secrets, 
      new[] { YouTubeService.Scope.Youtube }, 
      "user", 
      CancellationToken.None 
     ); 
     } 
     var youtubeService = new YouTubeService(new BaseClientService.Initializer() 
     { 
     HttpClientInitializer = credential, 
     ApplicationName = Assembly.GetExecutingAssembly().GetName().Name 
     }); 

     var videosDeleteRequest = youtubeService.Videos.Delete("Video ID"); 
     await videosDeleteRequest.ExecuteAsync(); 
    } 

但是,讓403響應

Error: Google.Apis.Requests.RequestError 
Insufficient Permission [403] 
Errors [ 
     Message[Insufficient Permission] Location[ - ] Reason[insufficientPermis 
sions] Domain[global] 
] 

一點幫助或任何可能的解決方案將是非常可觀的。

+0

你的驗證看起來是正確的,這也是正確的範圍,你確定你認證的用戶/頻道有該視頻ID?嘗試先做一個視頻列表來確保。 – DaImTo

+0

我們可以使用相同的連接上傳視頻,但是當我們嘗試獲取視頻列表或刪除視頻時,則此連接不起作用。它給了我們403迴應。 –

+0

感謝@DaImTo的幫助。現在我們可以使用具有訪問令牌的Google刪除API來刪除視頻。 –

回答

相關問題