Ramco Ramco

Ramco Ramco

  • 439
  • 3.4k
  • 544.6k

Short Video Tags And Country

Apr 3 2024 9:32 AM

Hi

  In below code i want to get Tags,Country etc.

        public void ShortVideosSports()
        {
            Int32 Count = 1;
            StringBuilder htmlTable = new StringBuilder();

            List<VideoListResponse.Item> listVideo = new List<VideoListResponse.Item>();

            var client = new RestClient("youtube/v3");
            var request = new RestRequest("search", Method.GET);
            request.AddParameter("part", "snippet");
            request.AddParameter("type", "video");
            request.AddParameter("order", "viewCount");

            DateTime twoDaysAgo = DateTime.UtcNow.AddDays(-2);
            string publishedAfter = twoDaysAgo.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'");
            request.AddParameter("publishedAfter", publishedAfter);
            request.AddParameter("key", "AJSTHSSTHSSG8");
            var response = client.Execute<YoutubeSearchListResponse>(request);

            Int32 ViewCount = 0;
            foreach (var data in response.Data.items)
            {
                var clientTag0 = new RestClient("youtube/v3/");
                var tagRequest0 = new RestRequest("videos", Method.GET);
                tagRequest0.AddParameter("key", "AIJSGSTSGYTSJSHHSGs8ECFG8");
                tagRequest0.AddParameter("part", "snippet,statistics");
                tagRequest0.AddParameter("order", "viewCount");
                tagRequest0.AddParameter("id", data.id.videoId);
                var tagResponse0 = clientTag0.Execute<VideoListResponse>(tagRequest0);

                foreach (var searchResult in tagResponse0.Data.items)
                {
                    listVideo.Add(searchResult);
                }
            }
            if (listVideo.Any())
            {
                htmlTable.Append("<table class='table table-bordered table-hover datatable-highlight' id='tbldata'>");
                //htmlTable.Append("<thead><tr><th>SN</th><th>Description</th><th> Tags </th></tr></thead>");
                htmlTable.Append("<thead><tr><th>SN</th><th>Channel Id</th><th>Channel Title</th><th>Video Title</th><th>Description</th><th>Views</th><th>Published</th></tr></thead>");
                htmlTable.Append("<tbody>");
                var orderByVideosCount = listVideo.OrderByDescending(x => x.statistics.viewCount);
                foreach (var item in orderByVideosCount)
                {

                    htmlTable.Append("<td>" + Count.ToString() + "</td>");


                    htmlTable.Append("<td >" + item.snippet.description + "</td>");

                    htmlTable.Append("<td>" + item.statistics.viewCount + "</td>");

                    htmlTable.Append("</tr>");
                    Count++;
                }
                htmlTable.Append("</tbody>");
                htmlTable.Append("</table>");
                PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
            }
        }

Thanks


Answers (1)