将视频上传到 youtube 时,我如何知道什么类别 id 是什么类别名称? [英] How do i know what category id is what category name when uploading a video to youtube?

查看:99
本文介绍了将视频上传到 youtube 时,我如何知道什么类别 id 是什么类别名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向 Yourube 上传视频:在form1构造函数中:

I'm uploading a video to yourube: In form1 constructor:

UserCredential credential;
            using (FileStream stream = new FileStream(@"D:\C-Sharp\Youtube-Manager\Youtube-Manager\Youtube-Manager\bin\Debug\client_secrets.json", FileMode.Open, FileAccess.Read))
            {
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
                    "user",
                    CancellationToken.None,
                    new FileDataStore("YouTube.Auth.Store")).Result;
            }
            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 = "Default Video Title";
            video.Snippet.Description = "Default Video Description";
            video.Snippet.Tags = new string[] { "tag1", "tag2" };
            video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
            video.Status = new VideoStatus();
            video.Status.PrivacyStatus = "public";
            var filePath = @"C:\Users\bout0_000\Videos\test.mp4";
            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {

                const int KB = 0x400;
                var minimumChunkSize = 256 * KB;

                var videosInsertRequest = youtubeService.Videos.Insert(video,
                    "snippet,status", fileStream, "video/*");
                videosInsertRequest.ProgressChanged +=
                    videosInsertRequest_ProgressChanged;
                videosInsertRequest.ResponseReceived +=
                    videosInsertRequest_ResponseReceived;
                videosInsertRequest.ChunkSize = minimumChunkSize * 4;
                videosInsertRequest.Upload();
            }

在这个例子中,我使用的是类别号 22

Here in this example i'm using category number 22

video.Snippet.CategoryId = "22";

只有在上传视频后,我才在我的视频中的 youtube 网站上看到此类别是:人与人博客

Only after uploaded the video i see in youtube site in my video that this category is: People & Blogs

如果我浏览此链接 https://developers.google.com/youtube/v3/docs/videoCategories/list 我可以在那里播放使用底部 OAuth 2.0 的授权请求.

If i'm browsing to this link https://developers.google.com/youtube/v3/docs/videoCategories/list i can play there with the Authorize requests using OAuth 2.0 on the bottom.

但我仍然不明白在哪里可以看到按名称和 ID 列出的所有类别的完整列表?例如: 姓名:People &博客 ID:22

But i still don't understand where i can see a full list of all categories by names and by id's ? For example: Name: People & Blogs Id: 22

找不到任何显示它的网站.

Couldn't find any site that show it.

推荐答案

进行 API 调用:

https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&regionCode={two-character-region}&key={YOUR_API_KEY}

API 将返回您选择的区域的所有类别(名称和 ID).注意同一类别在所有地区应该有相同的ID;但是,某些类别在某些区域不可用(这就是您必须调用 API 的原因……区域太多,无法以友好的方式列出所有可能的排列).

And the API will return all categories (names and IDs) for the region you selected. Note that the same category should have the same ID across all regions; however, some categories are not available in certain regions (which is why you must do the API call ... there are too many regions to list all the possible permutations in a friendly way).

这篇关于将视频上传到 youtube 时,我如何知道什么类别 id 是什么类别名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆