gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:20:42 24 4
gpt4 key购买 nike

我正在使用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, "*/*");

看一下这个线程: click

关于c# - C#Youtube api V3-值不能为空错误异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35817881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com