C# Youtube api V3 - 值不能为空错误异常



我正在使用C# Youtube Client API v3将字幕上传到我的视频中。上传视频工作正常(所以我想身份验证和凭据没有问题)。我已经尝试了类似问题中推荐的各种可能选项,但没有一个对我有用。

我的范围如下:

YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeForceSsl, YouTubeService.Scope.Youtubepartner

编辑:(根据一条评论中的要求在下面添加了与服务初始化相关的代码)

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

代码的其他重要部分如下:

        string zFile = @"subs.srt";
        using (var fileStream = new FileStream(zFile, FileMode.Open))
        {
            Caption cap = new Caption();
            cap.Snippet = new CaptionSnippet();
            cap.Snippet.VideoId = "_VIDEO_ID";
            cap.Snippet.Language = "en";
            cap.Snippet.Name = "Test";
            cap.Snippet.IsDraft = false;
            const int KB = 0x400;
            var minimumChunkSize = 256 * KB;

            CaptionsResource.InsertMediaUpload req = youtubeService.Captions.Insert(cap, "snippet" , fileStream, "*/*");
            req.Sync = true;
            req.ProgressChanged += videosInsertRequest_ProgressChanged;
            req.ChunkSize = minimumChunkSize * 8;
            //req.ResponseReceived += videosInsertRequest_ResponseReceived;
            IUploadProgress result = req.Upload();
        }

当我执行上述代码时,我得到的异常如下:

System.ArgumentNullException: Value cannot be null.
Parameter name: baseUri

请注意,我也已经尝试过snippet, status但没有帮助。

感谢社区的支持。

我认为您需要检查

CaptionsResource.InsertMediaUpload req = youtubeService.Captions.Insert(cap, "snippet" , fileStream, "*/*");

查看此线程:单击

相关内容

  • 没有找到相关文章

最新更新