我使用C#Youtube客戶端API v3將Caption上傳到我的視頻。視頻上傳工作正常(所以我認爲沒有認證和憑據問題)。我曾嘗試過類似問題中推薦的各種可能的選項,但他們都沒有爲我工作。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
也沒有幫助。
感謝來自社區的支持。
你在哪裏intialize youtubeService? 你能給這個代碼嗎? –
只需在編輯部分添加與youtubeService初始化相關的代碼。 – user1809095