Get All The Videos Of A YouTube Channel Using C#

Introduction

 
This is one of the social media implementations. Here we are fetching all the videos from a particular YouTube channel and showing in a console application
 
Description
 
We need to follow the following steps for implementing this application.
 
Step-1(Create an API Key)
 
Now before moving forward we should have a Google Developer account (e.g. any Google account).
 
Visit this URL. And it will come up like the following image.
 
create project
 
Now click on Create Project giving a project name and click Create. After this do as per the following image and follow the instructions.
 
 
After completing this a popup window will come and then click the Browser key. Now give a name and click Create. After this, you will get your API key by which you are going to get all the videos from a particular YouTube channel.
 
Step-2(Get Channel Name)
 
While fetching all the details of a particular channel we need to know the Channel Name.
 
See I am a die heart fan of Mumbai-Indians. Go to YouTube.com search Mumbai Indians as in the following image:
 
Youtube
 
You can see the 1st one is the channel as it has been written. Click on it you will get a URL as https://www.youtube.com/user/mipaltan.
 
Here mipaltan is the channel name. You can take any of your preferred channel names in this process.
 
Step-3(Programming)
 
Create a console application using visual studio.
 
Search and Install YouTube.V3 from the Nuget Package Manager Console.
 
Add your code as per below
  1. class Program  
  2.     {  
  3.         static void Main(string[] args)  
  4.         {  
  5.             try  
  6.             {  
  7.                 var yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "AIzaSyCT8kXaxJ2l29vYg4HBdYy36H-PhAH-Teg" });  
  8.                 var channelsListRequest = yt.Channels.List("contentDetails");  
  9.                 channelsListRequest.ForUsername = "mipaltan";  
  10.                 var channelsListResponse = channelsListRequest.Execute();  
  11.                 int VideoCount=1;  
  12.                 foreach (var channel in channelsListResponse.Items)  
  13.                 {  
  14.                     var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;  
  15.                     var nextPageToken = "";  
  16.                     while (nextPageToken != null)  
  17.                     {  
  18.                         var playlistItemsListRequest = yt.PlaylistItems.List("snippet");  
  19.                         playlistItemsListRequest.PlaylistId = uploadsListId;  
  20.                         playlistItemsListRequest.MaxResults = 50;  
  21.                         playlistItemsListRequest.PageToken = nextPageToken;  
  22.                         // Retrieve the list of videos uploaded to the authenticated user's channel.  
  23.                         var playlistItemsListResponse = playlistItemsListRequest.Execute();  
  24.                         foreach (var playlistItem in playlistItemsListResponse.Items)  
  25.                         {  
  26.                             Console.WriteLine("Sl No={0}", VideoCount);  
  27.                             Console.Write("Video ID ={0} ""https://www.youtube.com/embed/" + playlistItem.Snippet.ResourceId.VideoId);  
  28.                             //Console.Write("Video Title ={0} ", playlistItem.Snippet.Title);  
  29.                             //Console.Write("Video Descriptions = {0}", playlistItem.Snippet.Description);  
  30.                             //Console.WriteLine("Video ImageUrl ={0} ", playlistItem.Snippet.Thumbnails.High.Url);  
  31.                             //Console.WriteLine("----------------------");  
  32.                             VideoCount++;  
  33.                         }  
  34.                         nextPageToken = playlistItemsListResponse.NextPageToken;  
  35.                     }  
  36.                     Console.ReadLine();  
  37.                 }  
  38.             }  
  39.             catch (Exception e)  
  40.             {  
  41.                 Console.WriteLine("Some exception occured" + e);  
  42.             }  
  43.         }  
  44.     } 
 Note
  1. This code will list the Serial Number and  Video ID of all 202 videos.
  2. You can also add the commented things to get all the details.
For getting the latest video from a YouTube channel using Jquery find the link
 
You can download the attached code sample for reference. Hope that helps you.
 
Download the solution from this link.