0

YouTube チャンネルに動画をアップロードしようとすると、次のエラーが表示されます。

System.ArgumentException: 前提条件が失敗しました。: Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスク タスク) で !string.IsNullOrEmpty(authorization.RefreshToken) が Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(タスク タスク) で Microsoft.Runtime. 1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Upload.ResumableUploadc:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis . Release\bin\Debug\output\default\Src\GoogleApis\Apis[Media]\Upload\ResumableUpload.cs:356行目

コード:

   class Program
    {
        private const string SERVICE_ACCOUNT_EMAIL = "685082793570-acspgovnpo2dfmcb5fsqdu5e0q7pdmn1@developer.gserviceaccount.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

4

1 に答える 1

1

数週間前に発表された新しいリリース (1.6.0-beta) で (詳細については、こちらの発表ブログを参照してください)、さまざまな Windows プラットフォームとさまざまなフロー (サービス アカウントを含む) をサポートする新しい Auth ライブラリを紹介しました。

詳細については、OAuth2 ページ、具体的にはこちらをご覧ください。新しいライブラリには DNOA に依存関係が含まれていないため、使用とデバッグが非常に簡単になります。

お役に立てば幸いです。最新情報を入手してください。

于 2013-11-03T15:20:30.120 に答える