Hi
I have below code . I want to list No of Subscribers also.
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; }
}
Thanks
Tuhin PaulPosted Feb 28, 2025, 7:56 AM
API Quota :
channels) for each video, ensure you have sufficient quota or optimize the calls (e.g., batch requests if possible).Error Handling :
GetSubscriberCountmethod returns0if no data is found for a channel. You can enhance error handling as needed.Hidden Subscriber Counts :
hiddenSubscriberCountfield will betrue, and thesubscriberCountwill not be available.API Key :
"AIz8..."with your actual YouTube Data API key.Tuhin PaulPosted Feb 28, 2025, 7:56 AM
Added a New Column for Subscribers :
section of the HTML table now includes a new column:- Each row in the
Subscribers .section includes the subscriber count for the respective channel.-
- A new method
- This method makes a separate API call for each video's channel and retrieves the
-
- Inside the loop that processes each video, the
- The subscriber count is then appended to the HTML table.
-
- Added
- The
- For each video, it extracts the
- The subscriber count is displayed in the HTML table alongside other video details.


Helper Method to Fetch Subscriber Count :
GetSubscriberCountwas added to fetch the subscriber count for a givenchannelIdusing thechannelsendpoint of the YouTube Data API.subscriberCountfrom thestatisticspart of the response.Updated the Loop :
GetSubscriberCountmethod is called to fetch the subscriber count for the channel associated with the video.New Classes for Deserializing the
channelsEndpoint Response :ChannelResponse,ChannelItem, andStatisticsclasses to handle the response from thechannelsendpoint.MyOwnVideosmethod fetches the list of videos using thesearchendpoint.channelIdand calls theGetSubscriberCountmethod to fetch the subscriber count for the channel.Output Example
Video Id
Video Title
Description
Published
Subscribers
dQw4w9WgXcQ
Example Video Title
This is a test desc
2023-01-01T12:00:00
1,234,567
abc123xyz
Another Video
Another description
2023-02-15T15:30:00
987,654
Tuhin PaulPosted Feb 28, 2025, 7:55 AM
To include the number of subscribers for each video's channel in your code, you need to make an additional API call to the YouTube Data API. Specifically, you can use the
channelsendpoint with thestatisticspart to retrieve the subscriber count for the channel associated with each video.Daniel WrightPosted Feb 26, 2025, 1:33 AM
Hi! It seems like you're working on retrieving data about your own videos from YouTube's API. To list the number of subscribers for each video, you would typically need to make additional API calls to fetch that specific information.
Here's an overview of the steps you could take to include the number of subscribers along with the other video details:
1. Extend the `Snippet` class to include a property for the number of subscribers.
2. Modify your API request to fetch the subscriber count along with other video details.
3. Update your HTML table generation to display the subscriber count for each video.
For step 1, you can enhance the `Snippet` class like this:
For step 2, you would need to adjust your API call to include fetching the subscriber count. This might necessitate a different endpoint or an additional API call to get that specific information.
Finally, in step 3, once you have the subscriber count in the `Snippet` object, you can include it in your HTML table generation within the foreach loop. For example:
Remember that fetching subscriber count might require additional permissions or tokens from the YouTube API, so make sure to handle that accordingly.
If you encounter any challenges or have more specific requirements, feel free to ask for further assistance. Good luck with your YouTube API integration!