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();
}
Here in this example i'm using category number 22
video.Snippet.CategoryId = "22";
Only after uploaded the video i see in youtube site in my video that this category is: People & Blogs
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.
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.
Below is VB .NET source code from my program. This code loads a ComboBox with a Custom Class (CategoryClass) that includes all of the valid CategoryIds and Titles. I also included my Custom Class: CategoryClass. You can use one of the free converters to convert this to C# .NET.
Make an API call to:
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).