Hi
I want to get a list of my own youtube videos with details like
title,description,like,comments,subscribers.
Thanks
Hi
I want to get a list of my own youtube videos with details like
title,description,like,comments,subscribers.
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Ramco RamcoRank #462 · 5.4K reputationPosted Aug 21, 2024, 1:44 AM EDT
Hi Jignesh
It is o.k I deliberately changed this as it does not allow me to post on forum
Thanks
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 21, 2024, 12:00 AM EDT
Hello Ramco,
You can use below code snipet to get your video detail,
using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; using System; using System.Collections.Generic; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { // Initialize YouTube Service with your API Key var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "YOUR_API_KEY", // Replace with your API Key ApplicationName = "YouTubeDataAPI" }); // Retrieve the authenticated user's channel var channelRequest = youtubeService.Channels.List("snippet,statistics"); channelRequest.Mine = true; var channelResponse = await channelRequest.ExecuteAsync(); // Get the channel details string channelId = channelResponse.Items[0].Id; string channelTitle = channelResponse.Items[0].Snippet.Title; long subscriberCount = channelResponse.Items[0].Statistics.SubscriberCount ?? 0; // List videos uploaded by the authenticated user var searchListRequest = youtubeService.Search.List("snippet"); searchListRequest.ChannelId = channelId; searchListRequest.MaxResults = 50; // Change this to retrieve more videos searchListRequest.Type = "video"; var searchListResponse = await searchListRequest.ExecuteAsync(); List videos = new List(); foreach (var searchResult in searchListResponse.Items) { var videoId = searchResult.Id.VideoId; // Get video details var videoRequest = youtubeService.Videos.List("snippet,statistics"); videoRequest.Id = videoId; var videoResponse = await videoRequest.ExecuteAsync(); foreach (var video in videoResponse.Items) { videos.Add(video); Console.WriteLine("Title: " + video.Snippet.Title); Console.WriteLine("Description: " + video.Snippet.Description); Console.WriteLine("Likes: " + video.Statistics.LikeCount); Console.WriteLine("Comments: " + video.Statistics.CommentCount); Console.WriteLine("Subscribers: " + subscriberCount); Console.WriteLine(new string('-', 50)); } } } }Ramco RamcoRank #462 · 5.4K reputationPosted Aug 21, 2024, 12:49 AM EDT
Hi Jignesh
I am trying like below but in allitems it is showing count = 0
StringBuilder htmlTable = new StringBuilder(); var client = new RestClient("htps://www.googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.GET); request.AddParameter("part", "snippet"); request.AddParameter("type", "video"); request.AddParameter("channelId", "UCg3ZpngG-m_nNVw"); request.AddParameter("key", "AIzaSyAu9f5blG8"); List allItems = new List(); // Make initial request for youtube endpoint IRestResponse response = client.Execute(request); htmlTable.Append(""); htmlTable.Append("Video IdVideo TitleDescriptionViewsLikeCommentPublished"); htmlTable.Append(""); foreach (var data in allItems.OrderBy(x => x.snippet.publishedAt))Thanks
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 21, 2024, 1:28 AM EDT
Hello Ramco,
Looks like your URL is wrong, please check, "https://www.googleapis.com/youtube/v3",
StringBuilder htmlTable = new StringBuilder(); var client = new RestClient("https://www.googleapis.com/youtube/v3"); var request = new RestRequest("search", Method.GET); request.AddParameter("part", "snippet"); request.AddParameter("type", "video"); request.AddParameter("channelId", "UCg3ZpngG-m_nNVw"); // Replace with your channelId request.AddParameter("key", "AIzaSyAu9f5blG8"); // Replace with your API key // Make initial request for youtube endpoint IRestResponse response = client.Execute(request); if (response.IsSuccessful && response.Data != null) { List allItems = response.Data.items; htmlTable.Append(""); htmlTable.Append("Video IdVideo TitleDescriptionPublished"); htmlTable.Append(""); foreach (var data in allItems.OrderBy(x => x.snippet.publishedAt)) { htmlTable.Append(""); htmlTable.AppendFormat("{0}", data.id); htmlTable.AppendFormat("{0}", data.snippet.title); htmlTable.AppendFormat("{0}", data.snippet.description); htmlTable.AppendFormat("{0}", data.snippet.publishedAt); htmlTable.Append(""); } htmlTable.Append(""); htmlTable.Append(""); // Output the HTML table to the console or return it from a function Console.WriteLine(htmlTable.ToString()); } else { Console.WriteLine("Failed to retrieve data from YouTube API."); Console.WriteLine(response.ErrorMessage); }