Hi
In below code how to use PageToken so all the Videos gets displayed
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

Sophia CarterRank #4,018 · 371 reputationPosted Mar 23, 2025, 1:41 AM EDT
Hello! It looks like you're interested in using PageToken to display all the videos in your YouTube API call. Here's how you can incorporate PageToken into your code snippet:
When you make a request to the YouTube API to retrieve a list of videos, the response might be paginated. This means that the API may not return all videos in a single response but instead provide a token that you can use to fetch the next set of results.
To implement PageToken in your code for fetching all videos, you need to modify your existing code to handle pagination. Here's a general outline of how you can do this:
1. Add a variable to store the PageToken:
string pageToken = string.Empty;2. Modify your request to include the PageToken parameter:
request.AddParameter("pageToken", pageToken);3. After processing the current set of videos, check if there is a nextPageToken in the response:
if (!string.IsNullOrEmpty(response.Data.nextPageToken)) { pageToken = response.Data.nextPageToken; // Make another request with the new PageToken to fetch the next set of videos }4. Loop through the subsequent responses until all videos are fetched, updating the PageToken in each iteration.
By following these steps and handling the PageToken appropriately, you can retrieve all the videos associated with the channelId provided in your code.
I hope this explanation helps you integrate PageToken effectively into your code to fetch and display all the videos. If you need further assistance or clarification, feel free to ask!
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 23, 2025, 6:21 AM EDT
Hello Ramco,
You can use token as below,
protected void MyOwnVideos() { string nextPageToken = ""; // Initial page token is empty do { // Your other code if (!string.IsNullOrEmpty(nextPageToken)) { request.AddParameter("pageToken", nextPageToken); } // Your API call code here nextPageToken = response.Data.nextPageToken; } while (!string.IsNullOrEmpty(nextPageToken)); // Continue until there are no more pages // Your remaining code }Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 23, 2025, 7:46 AM EDT
Hello Ramco,
To fetch all videos, you need to handle pagination using the
pageToken. Below is an updated version of your code that retrieves all videos by iterating through all available pages.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"); // API max limit per 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; // Get the next page token } while (!string.IsNullOrEmpty(nextPageToken)); // Continue while there are more pages // 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()); }Good Luck!