gpt4 book ai didi

c# - C#在YouTube.Videos.Insert上使用YouTube API v3设置NotifySubscribers

转载 作者:行者123 更新时间:2023-12-03 05:31:33 24 4
gpt4 key购买 nike

我正在使用YouTube API v3将视频上传到YouTube。我目前可以上传视频,更新标题和描述,但是对我来说很重要的一点是取消选中( bool(boolean) 假)NotifySubscribers属性。

我已经能够找到herehere文档,但是没有任何实现示例,我感到非常迷茫。

以下是我当前可以成功上传的代码,而无需将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#编码,因此其中一些概念对我来说还是很新的。

最佳答案

事实证明,当前的Google.Apis.YouTube.v3 NuGet包(1.21.0.760)无法实现。看来他们在.dll中遗漏了许多方法,这导致功能非常有限。为了解决这个问题,我从this GitHub存储库中获取了代码,并将其放在自己的.cs文件中。然后,我可以调用此文件中的所有方法。完成此操作后,更改此设置所需要做的就是以下操作:

videosInsertRequest.NotifySubscribers = false;

关于c# - C#在YouTube.Videos.Insert上使用YouTube API v3设置NotifySubscribers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42180473/

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