List Videos From a Channel Using YouTube API V3 in C#

Google has retired YouTube API V2. If you try to fetch videos using the API V2 then you will get the error “410 Gone Away“. In this article, we will see how to retrieve all videos from a specific YouTube Channel using the latest YouTube API V3.

Let's get started by creating the application.

  • We create a new stand alone application named “YouTubeVideos” and install the Nuget package named “Google.Apis.YouTube.V3″ to the application. In case you're unaware of installing Nuget packages to your application, check it here.

youtube-1

youtube-2

  • Once the project has been created, “Select the project” and go to “APIs & Auth” and then “Credentials” from the left sidebar.

youtube-3

  • If you just want to retrieve videos, you can go ahead and click on “Create new Key” under Public API access. However, if you want to use oAuth to validate user credentials before showing them the videos, you need to create a Client ID. For this example, we will be using “Public API access”.
  • After the key is created, copy the key into a text file.
  • Returning to the application, the following is the complete code:
  1. using System;  
  2. using Google.Apis.YouTube.v3;  
  3. using Google.Apis.Services;  
  4.    
  5. namespace YoutubeVideos  
  6. {  
  7.     class Program  
  8.     {  
  9.         static void Main(string[] args)  
  10.         {  
  11.             YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "YOUR_API_KEY" });  
  12.    
  13.    
  14.             var searchListRequest = yt.Search.List("snippet");  
  15.             searchListRequest.ChannelId = "YOUR_CHANNEL_ID";  
  16.             var searchListResult = searchListRequest.Execute();  
  17.             foreach (var item in searchListResult.Items)  
  18.             {  
  19.                 Console.WriteLine("ID:" + item.Id.VideoId);  
  20.                 Console.WriteLine("snippet:" + item.Snippet.Title);  
  21.             }  
  22.         }  
  23.     }  

The preceding code will list the VideoID and Title of the videos present in your channel.

I hope this article helped you in retrieving YouTube videos from your channel. Let me know if you have any other way of doing so or have any questions via comments.

Up Next
    Ebook Download
    View all
    Learn
    View all
    Think. Innovate. Grow.