0

尝试将视频上传到我的 youtube 频道时出现以下错误:

System.ArgumentException: Precondition failed.: !string.IsNullOrEmpty(authorization.RefreshToken) at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Microsoft.Runtime。 CompilerServices.TaskAwaiter.ValidateEnd(Task task) 在 Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable 1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Upload.ResumableUpload1.d__0.MoveNext() 在 c:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis。 Release\bin\Debug\output\default\Src\GoogleApis\Apis[媒体]\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)中,(在我们的公告博客中阅读更多信息)我们展示了一个新的 Auth 库,它支持不同的 Windows 平台和不同的流程(包括服务帐户)。

在我们的 OAuth2 页面中阅读更多内容,特别是在此处。新库不再包含 DNOA 中的依赖项,因此它应该非常易于使用和调试。

希望对你有帮助,让我更新。

于 2013-11-03T15:20:30.120 回答