Hi
I am trying to get Most Popular Videos Region Wise & Category Wise using this API -
Thanks
Hi
I am trying to get Most Popular Videos Region Wise & Category Wise using this API -
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
Pasang TamangRank #449 · 5.6K reputationPosted Jan 12, 2023, 8:12 AM EST
Hi,
If you want to list out most popular videos then you have to specify filter rule so the API can gives you the most popular video list. With YouTube Data API I have done like in below code.
var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "" }); var youtubeRequest = youtubeService.Videos.List("snippet"); youtubeRequest.RegionCode = "US"; youtubeRequest.Chart = VideosResource.ListRequest.ChartEnum.MostPopular; youtubeRequest.MaxResults = 10; // shows 10 items as result var response = youtubeRequest.Execute(); foreach (var video in response.Items) { Console.WriteLine("{0} ({1})", video.Snippet.Title, video.Id); } Console.Read();Regards,
Pasang
Pasang TamangRank #449 · 5.6K reputationPosted Jan 12, 2023, 8:22 AM EST
And here is the code example how you can do it with Restsharp. In Restsharp you will get json content. So, you need to deserialize using Newtonsoft.Json.
var client = new RestClient("https://www.googleapis.com/youtube/v3/"); var request = new RestRequest("videos", Method.Get); request.AddParameter("part", "snippet"); request.AddParameter("regionCode", "IN"); request.AddParameter("chart", "mostPopular"); request.AddParameter("maxResults", 10); request.AddParameter("key", ""); var response = client.Execute(request); var json = response.Content; var content = JsonConvert.DeserializeObject(response.Content); foreach (var video in content.items) { Console.WriteLine("{0} ({1})", video.snippet.title, video.id); } Console.Read();public class Root { public string kind { get; set; } public string etag { get; set; } public List items { get; set; } public string nextPageToken { get; set; } public PageInfo pageInfo { get; set; } } public class Default { public string url { get; set; } public int width { get; set; } public int height { get; set; } } public class High { public string url { get; set; } public int width { get; set; } public int height { get; set; } } public class Item { public string kind { get; set; } public string etag { get; set; } public string id { get; set; } public Snippet snippet { get; set; } public Statistics statistics { get; set; } } public class Localized { public string title { get; set; } public string description { get; set; } } public class Maxres { public string url { get; set; } public int width { get; set; } public int height { get; set; } } public class Medium { public string url { get; set; } public int width { get; set; } public int height { get; set; } } public class PageInfo { public int totalResults { get; set; } public int resultsPerPage { get; set; } } public class Snippet { public DateTime publishedAt { get; set; } public string channelId { get; set; } public string title { get; set; } public string description { get; set; } public Thumbnails thumbnails { get; set; } public string channelTitle { get; set; } public List tags { get; set; } public string categoryId { get; set; } public string liveBroadcastContent { get; set; } public Localized localized { get; set; } public string defaultAudioLanguage { get; set; } public string defaultLanguage { get; set; } } public class Standard { public string url { get; set; } public int width { get; set; } public int height { get; set; } } public class Statistics { public string viewCount { get; set; } public string likeCount { get; set; } public string favoriteCount { get; set; } public string commentCount { get; set; } } public class Thumbnails { public Default @default { get; set; } public Medium medium { get; set; } public High high { get; set; } public Standard standard { get; set; } public Maxres maxres { get; set; } }Hope this helps to you.
Regards,
Pasang