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

Introduction

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.
    youtube-1
  • You also need an API Key from Google to be able to interface using the YouTube API.
  • Go to http://console.developers.google.com/ and create a project as in the following.
    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.
using System;  
using Google.Apis.YouTube.v3;  
using Google.Apis.Services;  
   
namespace YoutubeVideos  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "YOUR_API_KEY" });  
   
   
            var searchListRequest = yt.Search.List("snippet");  
            searchListRequest.ChannelId = "YOUR_CHANNEL_ID";  
            var searchListResult = searchListRequest.Execute();  
            foreach (var item in searchListResult.Items)  
            {  
                Console.WriteLine("ID:" + item.Id.VideoId);  
                Console.WriteLine("snippet:" + item.Snippet.Title);  
            }  
        }  
    }  
} 

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.


Similar Articles
Rebin Infotech
Think. Innovate. Grow.