Hi
How we can get Tags of Youtube video. I am using below code
C#
using (var yt = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "Api Key8",
}))
{
StringBuilder htmlTable = new StringBuilder();
var request = yt.Search.List("snippet");
request.Order = Google.Apis.YouTube.v3.SearchResource.ListRequest.OrderEnum.ViewCount;
request.MaxResults = 10;
var response = request.Execute();
var objResult = response.Items.ToList();Thanks

Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 1, 2023, 12:09 AM EST
new Program().GetTags(searchResult.Id.VideoId); //Get video Tags.
Instead of new Program() you need to use your class name : ex If GetTags method is inside class ABC than you need to write like
new ABC().GetTags(searchResult.Id.VideoId);
Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Jan 31, 2023, 11:24 PM EST
Hi Naimish
I want to get tags of most viewed youtube videos. In my last post i was able to get Video Title , Description , Channel Name etc . But with that i want Tags also. Is it possible
Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Jan 31, 2023, 11:46 PM EST
Hi
Possible to help with complete final code
Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Feb 1, 2023, 12:06 AM EST
Hi naimish
It is giving message The type or namespace name program does not exist.
new Program().GetTags(searchResult.Id.VideoId); //Get video Tags.
I am using Web based Asp.net c#
Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 31, 2023, 12:17 PM EST
Hello Ramco,
Please use below code.
private void GetTags() { var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "YOUR_KEY", ApplicationName = this.GetType().ToString() }); var request = youtubeService.Videos.List("snippet"); request.MaxResults = 10; request.Fields = "items(id,snippet(tags))"; request.Id = "ROGJzLUzIIs,VBJvDgBZEi4"; //Your videos ids commaseprated // Call the search.list method to retrieve results matching the specified query term. var searchListResponse = request.Execute(); foreach (var searchResult in searchListResponse.Items) { Console.WriteLine("-----------------"); Console.WriteLine(searchResult.Id); //This is your video id. Console.WriteLine("-----------------"); foreach (var tags in searchResult.Snippet.Tags) { Console.WriteLine(tags); } } }Please mark answer accepted if its useful.
Thanks
Naimish
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 31, 2023, 11:34 PM EST
Hello Ramco,
For most viewed videos, It is not possible.
But you can call given method in the response of most viewed videos response and by that way you can active what you want.
EX: In last ans:
foreach (var searchResult in searchListResponse.Items) { switch (searchResult.Id.Kind) { case "youtube#video": videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId)); // break; case "youtube#channel": channels.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId)); break; case "youtube#playlist": playlists.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId)); break; } }Let me know in case of any help.
Thanks
Naimish
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 1, 2023, 12:01 AM EST
Full code.
private void Run() { var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "REPLACE_ME", ApplicationName = this.GetType().ToString() }); var searchListRequest = youtubeService.Search.List("snippet"); searchListRequest.PublishedAfter = DateTime.Today; searchListRequest.PublishedBefore = DateTime.Today.AddDays(1); searchListRequest.Order = Google.Apis.YouTube.v3.SearchResource.ListRequest.OrderEnum.ViewCount; searchListRequest.Type = "video"; searchListRequest.VideoCategoryId = "10"; // Call the search.list method to retrieve results matching the specified query term. var searchListResponse = searchListRequest.Execute(); // Add each result to the appropriate list, and then display the lists of // matching videos, channels, and playlists. foreach (var searchResult in searchListResponse.Items) { switch (searchResult.Id.Kind) { case "youtube#video": new Program().GetTags(searchResult.Id.VideoId); //Get video Tags. break; } } } private void GetTags(string videoId) { var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "YOUR_KEY", ApplicationName = this.GetType().ToString() }); var request = youtubeService.Videos.List("snippet"); request.MaxResults = 10; request.Fields = "items(id,snippet(tags))"; request.Id = videoId; //Your videos ids commaseprated // Call the search.list method to retrieve results matching the specified query term. var searchListResponse = request.Execute(); foreach (var searchResult in searchListResponse.Items) { Console.WriteLine("-----------------"); Console.WriteLine(searchResult.Id); //This is your video id. Console.WriteLine("-----------------"); foreach (var tags in searchResult.Snippet.Tags) { Console.WriteLine(tags); //here you can get and store tag } } } }