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

时间:2016-03-05 18:16:28

标签: c# youtube youtube-api

我正在使用C#Youtube客户端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,但没有帮助。

感谢社区的支持。

1 个答案:

答案 0 :(得分:0)

我认为你需要检查

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

看看这个帖子:click