Hi
In below code i want that all Videos should get displayed. It displays only 50 Videos.
VB.NET
protected void MyOwnVideos()
{
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", "UC_nNoaVw"); // Replace with your actual channelId
request.AddParameter("key", "AIz8..."); // Replace with your actual API key
IRestResponse response = client.Execute(request);
// Check if the response contains data
if (response.Data == null || response.Data.items == null || response.Data.items.Count == 0)
{
Console.WriteLine("No Data Found. Please check your channelId and API key.");
return;
}
// Build the HTML table
htmlTable.Append("");
htmlTable.Append("Video IdVideo TitleDescriptionPublished");
htmlTable.Append("");
foreach (var data in response.Data.items.OrderBy(x => x.snippet.publishedAt))
{
htmlTable.Append("");
htmlTable.Append($"{data.id}");
htmlTable.Append($"{data.snippet.title}");
htmlTable.Append($"{data.snippet.description}");
htmlTable.Append($"{data.snippet.publishedAt}");
htmlTable.Append("");
}
htmlTable.Append("");
htmlTable.Append("");
// Output the HTML table
Console.WriteLine(htmlTable.ToString());
}Thanks

Jignesh KumarRank #91 · 22.9K reputationPosted Mar 23, 2025, 6:32 AM EDT
Hello Ramco,
You can use nextpageToken which you get from youtube API response, you need to use do --- While loop to get all videos from API response, Please use below code to get all videos.
protected void MyOwnVideos() { StringBuilder htmlTable = new StringBuilder(); var client = new RestClient("https://www.googleapis.com/youtube/v3"); string nextPageToken = ""; // Initial page token is empty string channelId = "UC_nNoaVw"; // Replace with your actual channelId string apiKey = "AIz8..."; // Replace with your actual API key htmlTable.Append(""); htmlTable.Append("Video IdVideo TitleDescriptionPublished"); htmlTable.Append(""); do { var request = new RestRequest("search", Method.GET); request.AddParameter("part", "snippet"); request.AddParameter("type", "video"); request.AddParameter("channelId", channelId); request.AddParameter("maxResults", "50"); // Max limit per page request.AddParameter("key", apiKey); if (!string.IsNullOrEmpty(nextPageToken)) { request.AddParameter("pageToken", nextPageToken); } IRestResponse response = client.Execute(request); if (response.Data == null || response.Data.items == null || response.Data.items.Count == 0) { Console.WriteLine("No Data Found. Please check your channelId and API key."); return; } foreach (var data in response.Data.items.OrderBy(x => x.snippet.publishedAt)) { htmlTable.Append(""); htmlTable.Append($"{data.id.videoId}"); htmlTable.Append($"{data.snippet.title}"); htmlTable.Append($"{data.snippet.description}"); htmlTable.Append($"{data.snippet.publishedAt}"); htmlTable.Append(""); } nextPageToken = response.Data.nextPageToken; } while (!string.IsNullOrEmpty(nextPageToken)); htmlTable.Append(""); htmlTable.Append(""); // Output the HTML table Console.WriteLine(htmlTable.ToString()); }Emily FosterRank #3,495 · 415 reputationPosted Mar 23, 2025, 1:29 AM EDT
Hey there! It seems like you're looking to display all videos from a specific YouTube channel in your code snippet. Currently, you're retrieving videos by using the YouTube Data API but only displaying 50 videos due to the default limit.
To display all videos, you can adjust your code to handle pagination and retrieve all available videos. Here are a few steps to consider:
1. Pagination: The YouTube Data API uses pagination to limit the number of results per page. You can make additional requests to get the next page of results until you have all the videos.
2. Update Request: Modify your existing code to handle pagination. You may need to make subsequent requests using the `pageToken` parameter to fetch the next set of results.
3. Loop through Pages: Implement a loop to continue fetching videos until there are no more pages left.
Here's a high-level overview of what you could do:
- Keep track of the `pageToken` returned in the API response.
- Make subsequent requests by adding the `pageToken` parameter with the value obtained from the previous response.
- Continue this process until you've fetched all the videos.
By incorporating pagination handling in your code, you will be able to retrieve and display all videos from the specified YouTube channel. If you need further assistance with the implementation or have any specific questions, feel free to ask!
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 23, 2025, 7:44 AM EDT
Hello Ramco,
By default, the YouTube Data API returns only 50 results per request. To fetch all videos, you need to handle pagination using the
nextPageToken. Modify your code to loop through all pages until there are no more results. Here is an updated code snippet:protected void MyOwnVideos() { StringBuilder htmlTable = new StringBuilder(); var client = new RestClient("https://www.googleapis.com/youtube/v3"); string nextPageToken = ""; List allVideos = new List(); do { var request = new RestRequest("search", Method.GET); request.AddParameter("part", "snippet"); request.AddParameter("type", "video"); request.AddParameter("channelId", "UC_nNoaVw"); // Replace with your actual channelId request.AddParameter("maxResults", "50"); // Max limit per API call request.AddParameter("key", "AIz8..."); // Replace with your actual API key if (!string.IsNullOrEmpty(nextPageToken)) { request.AddParameter("pageToken", nextPageToken); } IRestResponse response = client.Execute(request); if (response.Data?.items == null || response.Data.items.Count == 0) { Console.WriteLine("No Data Found."); break; } allVideos.AddRange(response.Data.items); nextPageToken = response.Data.nextPageToken; } while (!string.IsNullOrEmpty(nextPageToken)); // Build the HTML table htmlTable.Append(""); htmlTable.Append("Video IdVideo TitleDescriptionPublished"); htmlTable.Append(""); foreach (var data in allVideos.OrderBy(x => x.snippet.publishedAt)) { htmlTable.Append(""); htmlTable.Append($"{data.id.videoId}"); htmlTable.Append($"{data.snippet.title}"); htmlTable.Append($"{data.snippet.description}"); htmlTable.Append($"{data.snippet.publishedAt}"); htmlTable.Append(""); } htmlTable.Append(""); htmlTable.Append(""); // Output the HTML table Console.WriteLine(htmlTable.ToString()); }God Luck!
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 23, 2025, 2:29 PM EDT
The issue in your code is that the YouTube Data API v3 limits the number of results returned in a single request to 50 items by default. To retrieve more than 50 videos, you need to use pagination with the
pageTokenparameter. The API provides anextPageTokenin the response, which you can use to fetch the next set of results.Tuhin PaulRank #7 · 71.9K reputationPosted Mar 23, 2025, 2:30 PM EDT
protected void MyOwnVideos() { StringBuilder htmlTable = new StringBuilder(); var client = new RestClient("https://www.googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.GET); // Add required parameters request.AddParameter("part", "snippet"); request.AddParameter("type", "video"); request.AddParameter("channelId", "UC_nNoaVw"); // Replace with your actual channelId request.AddParameter("key", "AIz8..."); // Replace with your actual API key request.AddParameter("maxResults", "50"); // Maximum results per page (default is 50) string nextPageToken = null; bool hasMorePages = true; // Build the HTML table header htmlTable.Append(""); htmlTable.Append("Video IdVideo TitleDescriptionPublished"); htmlTable.Append(""); while (hasMorePages) { // Add nextPageToken to the request if it exists if (!string.IsNullOrEmpty(nextPageToken)) { request.AddParameter("pageToken", nextPageToken); } // Execute the API request IRestResponse response = client.Execute(request); // Check if the response contains data if (response.Data == null || response.Data.items == null || response.Data.items.Count == 0) { Console.WriteLine("No Data Found. Please check your channelId and API key."); break; } // Process the current page of results foreach (var data in response.Data.items.OrderBy(x => x.snippet.publishedAt)) { htmlTable.Append(""); htmlTable.Append($"{data.id.videoId}"); // Use videoId from the 'id' object htmlTable.Append($"{data.snippet.title}"); htmlTable.Append($"{data.snippet.description}"); htmlTable.Append($"{data.snippet.publishedAt}"); htmlTable.Append(""); } // Check if there are more pages nextPageToken = response.Data.nextPageToken; if (string.IsNullOrEmpty(nextPageToken)) { hasMorePages = false; // Exit the loop if no more pages } } // Close the HTML table htmlTable.Append(""); htmlTable.Append(""); // Output the HTML table Console.WriteLine(htmlTable.ToString()); }Pagination with
pageToken:nextPageTokenin the response when there are more results to fetch.pageTokenparameter.nextPageTokenis null).Dynamic Table Building:
Handling
videoId:idfield in the API response is an object containingvideoId. Ensure you access it correctly usingdata.id.videoId.Error Handling:
Max Results Per Page:
maxResultsparameter is explicitly set to 50 (the maximum allowed per request). You can reduce this if needed.