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; }
}
Sophia CarterPosted Mar 11, 2025, 1:01 AM
Hi there! It seems like you are working on a code snippet to retrieve and display videos from a specific YouTube channel based on a provided channelId. The code snippet fetches video details like Video Id, Title, Description, and Published Date using the YouTube Data API.
In order to list the No of Subscribers Video Wise, you might need to enhance the existing code logic. Subscribers count is not directly available in the search results; it typically requires an additional API request to fetch that information. You would need to utilize the YouTube channels list API to get the subscriber count for each video's channel.
Here's a high-level overview of how you could extend the functionality:
1. After fetching the video details, extract the channelId for each video from the response.
2. Make a separate API call to the YouTube channels list endpoint using the channelId to retrieve the subscriber count.
3. Integrate the subscriber count into your HTML table to display it alongside other video details.
By incorporating the subscriber count, you can provide a more comprehensive view of the videos based on their popularity in terms of subscribers. I hope this helps guide you in adding the No of Subscribers Video Wise feature to your project. If you need further assistance or more detailed code examples, feel free to ask!