Hi
I have below code and i want to get no of subscribers also with the video details
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("maxResults", 400);
request.AddParameter("channelId", "UCg3ZngG-m_nNoVw");
request.AddParameter("key", "AIzaSyYUSl87HSSG9b5Ls8ECKH8");
List allItems = new List();
IRestResponse response = client.Execute(request);
Thanks
Naimish MakwanaPosted May 20, 2024, 4:15 AM
To get the number of subscribers, you need to use the
channelsendpoint of the YouTube Data API. Thestatisticspart of the response will contain the subscriber count. Here’s how you can modify your code:In this code,
YoutubeChannelResponseis a class that you would need to define to deserialize the response from the YouTube Data API. It should include properties that match the structure of the API response.Please note that the subscriber count will only be visible if the channel has chosen to make this information public. If the channel has chosen to hide their subscriber count, this field will not be present in the API response. Also, please ensure that you have the necessary permissions and quota to make these API requests. You might need to handle API quota limits and pagination for large result sets.
Remember to replace
"UCg3ZngG-m_nNoVw"and"AIzaSyYUSl87HSSG9b5Ls8ECKH8"with your actual channel ID and API key. Be careful not to share your API key publicly. It’s a sensitive piece of information that can be used to access and modify your YouTube Data.Thanks
Abhishek ChadhaPosted May 19, 2024, 8:28 AM
To retrieve the number of subscribers along with the video details, you'll need to make an additional request to the YouTube Data API to fetch information about the channel. Below is an example of how you can modify your existing code to achieve this:
This code first retrieves video details using the provided
channelId, then for each video, it fetches the subscriber count for the corresponding channel using the samechannelId. Make sure to replace"YOUR_API_KEY"with your actual YouTube Data API key. Additionally, handle error cases appropriately in your actual application.