-2

我是來自youtube api的新成員。我希望有一個控制檯程序安排將視頻無需每次授權都上傳到YouTube。從Github運行Google.Apis.YouTube.Samples.Upload項目時授權失敗

我看到很多帖子和視頻,但沒有完整的故事,我從Github下載了示例並嘗試運行它。它失敗了。

我遵循指南,

.create OAuth用戶端ID和應用類型從GitHub

。點擊允許在瀏覽器中選擇其他

。下載代碼,讓YouTube的API管理的YouTube帳戶。

enter image description here

img1 - client secret download from console developer and code from github

img2 - error message told me unauthorized enter image description here

哪一部分是錯誤的,我怎麼能解決這個問題?請幫忙!

+0

今後就請發表您的代碼,而不是你的代碼 – DaImTo

+0

的屏幕截圖,請看看https://stackoverflow.com/help/formatting –

回答

0

錯誤您的獲得意味着您未驗證YouTubeService那裏必須有您的憑據錯誤,我不能看到,因爲您沒有發佈您的所有代碼。

YouTube API不支持服務帳戶。您至少需要驗證一次您的代碼。這是通過Web瀏覽器完成的,您正在使用的客戶端庫將「用戶」的憑據存儲在%appData%目錄中。

您正在關注的教程沒有提及任何關於不需要驗證的內容。這是auth的代碼。

UserCredential credential; 
     using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)) 
     { 
     credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
      GoogleClientSecrets.Load(stream).Secrets, 
      // This OAuth 2.0 access scope allows for full read/write access to the 
      // authenticated user's account. 
      new[] { YouTubeService.Scope.Youtube }, 
      "user", 
      CancellationToken.None, 
      new FileDataStore(this.GetType().ToString()) 
     ); 
     } 
+0

示例程序還包括您所提供的部分代碼。我是新的,所以我只能在帖子中發佈兩個鏈接。 – lei

+0

https://developers.google.com/youtube/v3/code_samples/dotnet – DaImTo

+0

@達爾姆,與您的完全一樣,但錯誤未經授權。網絡,代理,防火牆是否影響? – lei