我使用YouTube API v3将视频上传到YouTube。我目前能够上传视频,更新标题和说明,但对我而言非常重要的是取消选中(boolean false)NotifySubscribers属性。C#设置YouTube上的NotifySubscribers .Videos.Insert与YouTube API v3
我已经能够找到文档here和here,但没有任何实现的例子,我感觉很迷茫。
以下是我的代码目前有能够成功上传,无需NotifySubscribers设置为false:
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("youtube_client_secret.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "test";
video.Snippet.Description = "test description";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
var filePath = @"D:\directory\YoutubeUploader\2017-02-05_02-01-32.mp4";
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
await videosInsertRequest.UploadAsync();
}
}
void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
{
switch (progress.Status)
{
case UploadStatus.Uploading:
Console.WriteLine("{0} bytes sent.", progress.BytesSent);
break;
case UploadStatus.Failed:
Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
break;
}
}
我本来以为,设置该值会一直如设置标题一样简单,隐私身份等等,但这似乎并非如此。我从来没有做过任何真正深入的C#编码,因此其中一些概念对我来说是非常新的。
尝试更改隐私状态公众,这[论坛](https://productforums.google.com/forum/# !topic/youtube/GjIoVHR3f7M; context-place = topicsearchin/youtube/category $ 3Asafari)讨论过,任何视频上传为私有/不公开,都可能导致该用户不被通知。如果您已为每次上传完成手动勾选通知订阅者,请查看您的YouTube频道。默认情况下,[notifySubscribers](https://developers.google.com/youtube/v3/docs/videos/insert#parameters)设置为** True **。 –