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 17, 2025, 9:01 PM
To get the subscriber count, you'll need to make an additional API call to the YouTube Data API's "channels" endpoint.
Key changes made:
data.idtodata.id.videoId):N0format specifierThe subscriber count will now appear above the video table. Note that some channels might have their subscriber count hidden, in which case the
hiddenSubscriberCountproperty will be "true" andsubscriberCountwill not be available.To use this code, make sure you have:
Ramco RamcoPosted Feb 17, 2025, 11:53 AM
Hi Imran
Will it return no of subscribers each video wise or total no of subscribers. I want video wise subscribers
Thanks
Naimish MakwanaPosted Feb 17, 2025, 4:53 AM
To list the number of subscribers for your YouTube channel, you'll need to make an additional API call to the YouTube Data API to fetch the channel details. Here's how you can modify your code to include the number of subscribers:
MyOwnVideosmethod to call this new method and include the subscriber count in the HTML table.Here's the updated code:
This code adds a new method,
GetChannelDetails, which fetches the channel statistics, including the subscriber count. TheMyOwnVideosmethod is updated to include the subscriber count in the HTML table.Thanks
Muhammad Imran AnsariPosted Feb 16, 2025, 4:33 PM
Hello Ramco,
To include the number of subscribers for the YouTube channel in your code, you need to make an additional API call to the
channelsendpoint of the YouTube Data API. This endpoint provides channel statistics, including the subscriber count.Here’s how you can modify your code to include the number of subscribers:
Add a method to fetch channel statistics.
Update the
MyOwnVideosmethod to include the subscriber count.Here’s the updated code:
Good Luck!
nirajPosted Feb 16, 2025, 2:12 PM
It appears you are looking to extract the number of subscribers for a specific YouTube channel. In the given code snippet, you are retrieving video details based on a provided channel ID. To get the number of subscribers, you would typically need to make use of the YouTube Data API endpoint specifically designed to fetch channel information, including subscriber count.
To achieve this, you can modify your existing code to include an additional request to fetch the channel information. Here is an outline of steps you might take:
1. Update the endpoint to retrieve channel information based on the channel ID.
2. Parse the response to extract the subscriber count from the channel data.
3. Incorporate the subscriber count into your HTML table or output as needed.
Emily FosterPosted Feb 16, 2025, 1:46 PM
It appears you are looking to extract the number of subscribers for a specific YouTube channel. In the given code snippet, you are retrieving video details based on a provided channel ID. To get the number of subscribers, you would typically need to make use of the YouTube Data API endpoint specifically designed to fetch channel information, including subscriber count.
To achieve this, you can modify your existing code to include an additional request to fetch the channel information. Here is an outline of steps you might take:
1. Update the endpoint to retrieve channel information based on the channel ID.
2. Parse the response to extract the subscriber count from the channel data.
3. Incorporate the subscriber count into your HTML table or output as needed.
Here's a simplified example of how you could modify your existing code snippet to include subscriber count retrieval:
In this code snippet, `YoutubeChannelListResponse` would be a class similar to `YoutubeSearchListResponse` but tailored to channel information. By fetching the channel statistics, including the subscriber count, you can enrich your video listing with this additional data.
Feel free to integrate this logic into your existing code and adapt it to best suit your requirements. Let me know if you need further clarification or assistance with the implementation!