List Videos From a Channel using YouTube API V3 in C#
Friends,
Google has retired YouTube API V2 and trying to fetch videos using the API V2 returns an error as “410 Gone Away“. In this post, we will see how can we retrieve all videos from a specific YouTube Channel using the latest YouTube API V3.
Let’s get started 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 out here.
- You also need an API Key from Google to be able to talk using YouTube API.
- Go to https://console.developers.google.com/ and Create a Project
- Once the project gets created, “Select the project” and go to “APIs & Auth” > “Credentials” from the left sidebar.
- 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 videos, you need to create Client ID. For this example, we will be using “Public API access”.
- After the key is created, copy the key in a notepad file.
- Coming back to the application, below 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 above 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 in case you have any other way of doing so or need any help.