Hi
I have below code and i want to display my all Videos. Currently it is displaying only 50.
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());
}
public class YoutubeSearchListResponse
{
public string kind { get; set; }
public string etag { get; set; }
public string nextPageToken { get; set; }
public string regionCode { get; set; }
public PageInfo pageInfo { get; set; }
public List- items { get; set; }
}
public class Snippet
{
public DateTime publishedAt { get; set; }
public string channelId { get; set; }
public string title { get; set; }
public string description { get; set; }
public Thumbnail thumbnails { get; set; }
public string channelTitle { get; set; }
public string liveBroadcastContent { get; set; }
public DateTime publishTime { get; set; }
}
public class Id
{
public string kind { get; set; }
public string videoId { get; set; }
}
public class Item
{
public string kind { get; set; }
public string etag { get; set; }
public Id id { get; set; }
public Snippet snippet { get; set; }
}
Jignesh KumarPosted Mar 23, 2025, 10:29 AM
Hello Ramco,
Please chek your previous question where I have answered,
https://www.csharp.com/forums/how-to-use-pagetoken
Emily FosterPosted Mar 22, 2025, 4:05 PM
To display all your YouTube videos instead of just 50, you need to handle pagination in your code. YouTube's API returns a maximum of 50 results per page by default. To retrieve all videos, you can utilize the `nextPageToken` provided in the API response.
Here's how you can modify your existing code to fetch and display all videos from your channel:
1. Make changes in your `MyOwnVideos` method to handle pagination:
By passing the `nextPageToken` in subsequent API calls, you can retrieve all the videos from your channel.
2. Update your method invocation to start fetching videos from the beginning:
With these changes, your code will retrieve and display all videos from your YouTube channel by handling pagination through the `nextPageToken`. This ensures that you get a complete list of your videos instead of being limited to the default 50 results.