Hi
I have below code . I want to list No of Subscribers Video Wise.
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; }
}
Eliana BlakePosted Mar 13, 2025, 4:00 PM
Hi there! It seems like you're working on fetching and displaying YouTube videos based on a specific channelId using the YouTube Data API. In your provided code snippet, you are making a request to the YouTube API to retrieve video information like title, description, and publish date.
To list the number of subscribers for each video, you would typically need to make additional calls to the YouTube Data API endpoints that provide channel information, as the subscriber count is associated with the channel rather than individual videos.
Here's a high-level overview of how you could approach this:
1. Retrieve Channel Information: Modify your existing code to fetch the channel information (including the subscriber count) based on the channelId you are already using.
2. Associate Subscribers with Videos: Once you have the channel information with the subscriber count, you can then associate this subscriber count with each video when displaying them in your HTML table.
For example, after fetching the channel information, you could update your HTML table generation loop to include the subscriber count related to each video.
Remember to account for any rate limits or quotas imposed by the YouTube API to ensure that your requests are managed effectively.
Feel free to ask if you need more specific guidance or assistance with integrating subscriber counts into your video listing code!