2013-10-08 34 views
0

我在嘗試視頻上傳到我的YouTube頻道時,此以下錯誤:谷歌.NET客戶端的Youtube V3錯誤

System.ArgumentException:前提條件失敗:string.IsNullOrEmpty(authorization.RefreshToken) 在Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任務task) 在Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(任務task) 在Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任務task) 在Microsoft.Runtime。 CompilerServices.ConfiguredTaskAwaitable 1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Upload.ResumableUpload 1.d__0.MoveNext()in c:\ code.google.com \ google-api-dotnet-client \ d efault_3 \工具\ Google.Apis.Release \ BIN \調試\輸出\ DEFAULT \ SRC \ GoogleApis \蜜蜂[媒體] \上傳\ ResumableUpload.cs:線356

驗證碼:

class Program 
    { 
     private const string SERVICE_ACCOUNT_EMAIL = "[email protected]account.com"; 
     private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"97b6020dc5777485250124e25b788e4b8ed3324e-privatekey.p12"; 

     static YouTubeService BuildService() 
     { 
      var certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret",X509KeyStorageFlags.Exportable); 

      var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate) 
      { 
       ServiceAccountId = SERVICE_ACCOUNT_EMAIL, 
       Scope = YouTubeService.Scopes.YoutubeUpload.GetStringValue()   }; 
      var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState); 

      return new YouTubeService((new BaseClientService.Initializer() 
          { 
           Authenticator = auth, 
           ApplicationName = "Drive API Sample", 
          })); 
     } 

     static void Main(string[] args) 
     { 
      var youtube = BuildService(); 

      var video = new Video(); 
      video.Snippet = new VideoSnippet(); 
      video.Snippet.Title = "Video title"; 
      video.Snippet.Description = "Video description"; 
      video.Snippet.Tags = new string[] { "tag1", "tag2" }; 
      video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list 
      video.Status = new VideoStatus(); 
      video.Status.PrivacyStatus = "public"; // "Video privacy (public, private, or unlisted)"; 
      var filePath = "52224a59-2029-43fd-806b-efc434256c25.mp4"; 
      var fileStream = new FileStream(filePath, FileMode.Open); 

      var videosInsertRequest = youtube.Videos.Insert(video, "snippet,status", fileStream, "video/*"); 
      var upload = videosInsertRequest.Upload(); 
      Console.WriteLine(upload.BytesSent); 
      Console.WriteLine(upload.Status); 
      Console.WriteLine(upload.Exception); 
} 
} 

任何想法爲什麼會發生這種情況?
我使用Google.Apis DotNetOpenAuth版本的版本1.5.0.28972:4.0.0.11165

+0

我認爲這個問題是由於未在YouTube上正常註冊{ 「錯誤」:{ 「錯誤」:[{ 「域」: 「youtube.header」, 「理由」:「youtubeSignupRequired 」, 「消息」: 「未授權」, 「的locationType」: 「首標」, 「位置」: 「授權」 } ], 「代碼」:401, 「消息」: 「未授權」 } } – sanjosep43

+0

我們剛剛發佈了一個新的Auth庫,它可以讓您的生活更輕鬆。閱讀https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Service_Account_(available_only_on_.NET_framework_4)中的更多內容,並下載我們的Google.Apis.Auth NuGet包。祝你好運! – peleyal

回答

1

在新版本(1.6.0-β),這是幾個星期前宣佈,(詳情請閱讀我們的博客公告here)我們提出了一個新的Auth庫,它支持不同的Windows平臺和不同的流程(包括服務帳戶)。

請參閱我們的OAuth2頁面,特別是here。新的庫不再包含對DNOA的依賴,所以它應該很容易使用和調試。

希望它是有益的,讓我更新。

相關問題