【问题标题】:C# Youtube api V3 - Value cannot be null error exceptionC# Youtube api V3 - 值不能为空错误异常
【发布时间】:2016-06-19 11:26:41
【问题描述】:

我正在使用 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 但没有帮助。

感谢社区的支持。

【问题讨论】:

  • 你在哪里初始化 youtubeService?你能给出那个代码吗?
  • 刚刚在 Edit 部分添加了与 youtubeService 初始化相关的代码。

标签: c# youtube youtube-api


【解决方案1】:

我想你需要检查一下

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

看看这个帖子:click

【讨论】:

  • 实际上我之前看过那个线程,甚至在那个线程中,他也遇到了与我相同的错误,但没有帮助。我还提到我已经尝试过 "sn-p" 和 "sn-p, status" 但在这两种情况下我都得到了同样的错误。
猜你喜欢
  • 2014-09-03
  • 2015-04-28
  • 1970-01-01
  • 2016-11-28
  • 2015-12-12
  • 2020-03-01
  • 1970-01-01
  • 2013-10-04
  • 2015-08-10
相关资源
最近更新 更多