Hi
In below code how to use PageToken so all the Videos gets displayed
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 Id Video Title Description Published ");
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
Muhammad Imran AnsariPosted Mar 23, 2025, 11:46 AM
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.Good Luck!
Jignesh KumarPosted Mar 23, 2025, 10:21 AM
Hello Ramco,
You can use token as below,
Sophia CarterPosted Mar 23, 2025, 5:41 AM
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:
2. Modify your request to include the PageToken parameter:
3. After processing the current set of videos, check if there is a nextPageToken in the response:
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!