Hi
Is it possible to get Tags and Category of short video of YouTube
Thanks
Hi
Is it possible to get Tags and Category of short video of YouTube
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
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 11:40 AM EST
Hello Ramco,
To get CategoryId = 10 videos.
Add below parameter in "var request = new RestRequest("search", Method.Get);"
request.AddParameter("videoCategoryId", "10");Thanks
Naimish Makwana
Ramco RamcoRank #462 · 5.4K reputationPosted Feb 2, 2023, 11:06 AM EST
Hi Naimish
ON this line it is giving error - if (response.IsSuccessStatusCode).
Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 11:10 AM EST
Hello Ramco.
Remove that line for a while. and check.
My be the issue due to your RestSharp version.
The given code is tested and fully working.
Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Feb 2, 2023, 11:36 AM EST
Hi Naimish
Suppose i want only Category Id=10 videos what i need to changr
Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 9:33 AM EST
Hello Ramco,
You can get tags and category of short video like below.
static void Main(string[] args) { new ShortYouTubeVideo().GetShortVideo(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } public void GetShortVideo() { var client = new RestClient("https://www.googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.Get); request.AddParameter("part", "snippet"); request.AddParameter("q", "short videos category"); request.AddParameter("type", "video"); request.AddParameter("maxResults", 50); request.AddParameter("order", "viewCount"); request.AddParameter("key", "YOUR_KEY"); var response = client.Execute(request); if (response.IsSuccessStatusCode) { foreach (var data in response.Data.items) { // GetTags(data.id.videoId); Console.WriteLine(data.id.videoId); var clientTag = new RestClient("https://www.googleapis.com/youtube/v3/"); var tagRequest = new RestRequest("videos", Method.Get); tagRequest.AddParameter("key", "YOUR_KEY"); tagRequest.AddParameter("part", "snippet"); tagRequest.AddParameter("maxResults", 10); tagRequest.AddParameter("fields", "items(id,snippet(tags,categoryId))"); tagRequest.AddParameter("id", data.id.videoId); var tagResponse = clientTag.Execute(tagRequest); if (tagResponse.IsSuccessStatusCode) { foreach (var searchResult in tagResponse.Data.Items) { Console.WriteLine("categoryId => " + searchResult.Snippet.categoryId); //This is your categoryId. if (searchResult.Snippet != null && searchResult.Snippet.Tags != null) { foreach (var tags in searchResult.Snippet.Tags) { Console.WriteLine(tags); //here you can get and store tag } } } } } } }You can get YoutubeSearchListResponse class and YouTubeSearchResponse from below answer.
https://www.c-sharpcorner.com/Forums/using-restsharp-api
Just replace below class
public class TagSnippet { public List Tags { get; set; } public string categoryId { get; set; } }Thanks
Naimish Makwana