Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 512.7k

How to display list of all Videos

Apr 29 2024 12:15 PM

Hi

  I have below code and i want that it should display all Videos. It displays only 50 videos

            StringBuilder htmlTable = new StringBuilder();

            var client = new RestClient("googleapis.com/youtube/v3");
            var request = new RestRequest("search", Method.GET);
            request.AddParameter("part", "snippet");
            
            request.AddParameter("type", "video");
            request.AddParameter("channelId", "UCg3-m_nNoaVw");
            request.AddParameter("key", " AIzaSs8ECFG8");

            var response = client.Execute<YoutubeSearchListResponse>(request);
            var orderByPublishAt = response.Data.items.OrderBy(x => x.snippet.publishedAt);
            htmlTable.Append("<table class='table table-bordered table-hover datatable-highlight' id='tbldata'>");
            htmlTable.Append("<thead><tr><th>Video Id</th><th>Video Title</th><th>Description</th><th>Views</th><th>Like</th><th>Comment</th><th>Published</th></tr></thead>");
            htmlTable.Append("<tbody>");
            foreach (var data in orderByPublishAt)
            {
                var clientTag = new RestClient("googleapis.com/youtube/v3/");
                var tagRequest = new RestRequest("videos", Method.GET);
                tagRequest.AddParameter("key", "AIzaSs8ECFG8");
                tagRequest.AddParameter("part", "snippet,statistics");
                tagRequest.AddParameter("id", data.id.videoId);
                var tagResponse = clientTag.Execute<VideoListResponse>(tagRequest);

                foreach (var item in tagResponse.Data.items)
                {
 
                    htmlTable.Append("<td >" + item.snippet.title + "</td>");
                    htmlTable.Append("<td >" + item.snippet.description + "</td>");
                    
                    htmlTable.Append("</tr>");
                }
            }
            htmlTable.Append("</tbody>");
});
        }

Thanks


Answers (7)