Hi
How we can get Youtube Category List with their names.
Thanks
Hi
How we can get Youtube Category List with their names.
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal JoshiRank #377 · 6.7K reputationPosted Jan 12, 2023, 12:23 AM EST
Hello
You can call the below API to get data.
https://www.googleapis.com/youtube/v3/videoCategories?part=snippet®ionCode={two-character-region}&key={YOUR_API_KEY}API will return all categories (names and IDs) for the region you selected
Thanks
Amit MohantyRank #112 · 20K reputationPosted Jan 12, 2023, 12:22 AM EST
Try this
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; // create a new YouTube service var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "YOUR_API_KEY", ApplicationName = "YOUR_APP_NAME" }); // make a GET request to the videoCategories resource var categoriesListRequest = youtubeService.VideoCategories.List("snippet"); categoriesListRequest.RegionCode = "IN"; var categoriesListResponse = categoriesListRequest.Execute(); // iterate through the list of video categories foreach (var category in categoriesListResponse.Items) { // display the category name and id Console.WriteLine("{0} ({1})", category.Snippet.Title, category.Id); }Pasang TamangRank #449 · 5.6K reputationPosted Jan 12, 2023, 3:23 AM EST
Hi,
API URL given by Vishal is correct. You forgot to remove {} from the exampla link. It should be like below
var client = new RestClient("https://www.googleapis.com/youtube/v3/videoCategories?part=snippet®ionCode=IN&key=AIzaSyAu9f7blF7idzt6cGul59UQ9b2Ls8EXKG8");Regards,
Pasang
Pasang TamangRank #449 · 5.6K reputationPosted Jan 12, 2023, 12:34 AM EST
Hi,
For this first you need to create a project in Google Developer Console. You can check below links to create a project and API key in Google Developer Console
https://support.google.com/googleapi/answer/6251787?hl=en#zippy=%2Ccreate-a-project
https://support.google.com/googleapi/answer/6158862?hl=en
Then in your project you have to install Google.Apis.YouTube.v3 plugin from nuget. And then you can follow below code
using Google.Apis.Services; using Google.Apis.YouTube.v3; namespace ConsoleApp1; class ConsoleApp1 { static void Main(string[] args) { var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "", }); var youtubeRequest = youtubeService.VideoCategories.List("snippet"); youtubeRequest.RegionCode = "US"; var response = youtubeRequest.Execute(); foreach (var category in response.Items) { Console.WriteLine("{0} ({1})", category.Snippet.Title, category.Id); } Console.Read(); } }Regards,
Pasang
Pasang TamangRank #449 · 5.6K reputationPosted Jan 12, 2023, 12:37 AM EST
Forgot to include note about enabling Youtube Data API. You need to enable YouTube Data API service in your project in Google Developer console. You can check this link https://support.google.com/googleapi/answer/6158841?hl=en.
Regards,
Pasang
Ramco RamcoRank #462 · 5.4K reputationPosted Jan 12, 2023, 3:19 AM EST
Hi Vishal
I am getting this error - {
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"errors": [
{
"message": "API key not valid. Please pass a valid API key.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_INVALID",
"domain": "googleapis.com",
"metadata": {
"service": "youtube.googleapis.com"
}
}
]
}
}
var client = new RestClient("https://www.googleapis.com/youtube/v3/videoCategories?part=snippet®ionCode={IN}&key={AIzaSyAu9f7blF7idzt6cGul59UQ9b2Ls8EXKG8}"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", "application/json"); IRestResponse response0 = client.Execute(request); Console.WriteLine(response0.Content);Thanks