Hi
In below code i want data to be ordered by PublishedAT
var client = new RestClient("googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.Get); request.AddParameter("part", "snippet"); request.AddParameter("q", "sports shorts"); request.AddParameter("type", "video"); request.AddParameter("maxResults", 50); request.AddParameter("order", "viewCount"); request.AddParameter("videoDuration", "short"); var today = DateTime.Now.Date; var sevenDaysAgo = today.AddDays(-1).ToString("yyyy-MM-ddTHH:mm:ssZ"); request.AddParameter("publishedAfter", sevenDaysAgo); request.AddParameter("key", "API_KEY"); var response = client.Execute<YoutubeSearchListResponse>(request); List<VideoListResponse.Item> listVideo = new List<VideoListResponse.Item>(); foreach (var data in response.Data?.items) { var clientTag = new RestClient("googleapis.com/youtube/v3/"); var tagRequest = new RestRequest("videos", Method.Get); tagRequest.AddParameter("key", "API_KEY"); tagRequest.AddParameter("part", "snippet,statistics"); tagRequest.AddParameter("maxResults", 100); request.AddParameter("order", "viewCount"); tagRequest.AddParameter("id", data.id.videoId); var tagResponse = clientTag.Execute<VideoListResponse>(tagRequest); foreach (var item in tagResponse.Data.items) { Console.WriteLine("viewCount" + item.statistics.viewCount); Console.WriteLine("likeCount" + item.statistics.likeCount); Console.WriteLine("commentCount" + item.statistics.commentCount); var categoryId = item.snippet.categoryId; var clientCategory = new RestClient("googleapis.com/youtube/v3/"); var categoryRequest = new RestRequest("videoCategories", Method.Get); categoryRequest.AddParameter("key", "ApiKey8"); categoryRequest.AddParameter("part", "snippet"); categoryRequest.AddParameter("id", categoryId); var categoryResponse = clientCategory.Execute<VideoCategoryListResponse>(categoryRequest); if (categoryResponse.Data?.Items != null) { Console.WriteLine("CtegoryName " + categoryResponse.Data.Items[0].Snippet.Title); } } }
Thanks