首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C#使用YouTube API v3在YouTube.Videos.Insert上设置NotifySubscribers

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

Stack Overflow用户
提问于 2017-02-12 03:48:07
回答 1查看 304关注 0票数 1

我正在使用YouTube接口v3上传视频到YouTube。我目前可以上传视频,更新标题和描述,但对我来说非常重要的是取消选中(布尔值为false) NotifySubscribers属性。

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

以下是我目前拥有的能够成功上传的代码,而不需要将NotifySubscribers设置为false:

代码语言:javascript
运行
复制
        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#编码,所以其中一些概念对我来说是非常新的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-17 11:20:15

事实证明,对于当前的Google.Apis.YouTube.v3 NuGet包(1.21.0.760),这是不可能的。看起来他们把很多方法留在了.dll之外,这导致了非常有限的功能。为了解决这个问题,我从this GitHub存储库中提取代码,并将其放入自己的.cs文件中。然后我就可以调用这个文件中的所有方法了。完成此操作后,我只需执行以下操作即可更改此设置:

代码语言:javascript
运行
复制
videosInsertRequest.NotifySubscribers = false;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42180473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档