YouTube API with .NET 8 📺


Hey Reader,

I've always been curious about tinkering with YouTube's API using .NET—like fetching all the videos from any channel, updating video descriptions, and more. If that sounds like your cup of tea, you'll want to stick around.

This Week's Video: YouTube API with .NET 8 📺

In the latest video, I walk you through the initial steps for working with the YouTube API via a .NET Web API. We kick things off by securing the necessary credentials and proceed to list out all the videos from any channel (yes, not just yours!) in an easy-to-read format using a Data Transfer Object (DTO). Check out the video below.

video preview

Essential Code Highlights 🖥️

If you're someone who'd rather dive straight into the code, no worries, I've got your back.

First things first, grab the "Google.Apis.YouTube.v3" NuGet Package.

To obtain your YouTube API key, just follow the guide over here: YouTube API Getting Started.

Let's jump into coding!

Initially, you'll want to build two models: one for the specific video details and another for the collective response. We'll only need one controller method to get this rolling.

Now onto crafting the controller method. I've included two parameters: a pageToken and the max number of results. Please note, the API caps your request at 50 results, so the pageToken is your ticket to more.

We'll initiate by creating a YouTubeService instance and laying out the search query.

With the ChannelId, you can specify the channel you want the videos from—and this can be any channel, not just your own! We then sort the videos by their release date and request for a "snippet", which will return just the relevant info like title, description, and thumbnails. After that, we execute the query and build our response in a way that's more convenient for us.

Lastly, we formulate our YouTubeResponse using the list of videos and the tokens for navigating to the next and previous pages.

That's the whole shebang!

For the full code rundown, either watch the video or head to my ​Patreon​ for the repository download.


💌 If you've got questions or particular topics on your mind, just hit 'reply'—your feedback is golden. A big shoutout to everyone who makes this community so awesome! 🙌 Extra gratitude to my ​Patrons​ for powering this newsletter and the YouTube channel.

Catch you on our next coding adventure. Take care and code on! 💻

Patrick


Patrick God

Become a .NET & Blazor expert with weekly tutorials featuring best practices and the latest improvements, right in your inbox.

Read more from Patrick God

Hey friend, I just released a new video and I think you will enjoy this one. In the video, I ask GitHub Copilot to build a real mortgage app in Blazor. The app works. But the code is messy. All the business logic ends up in the UI. Fast results. Bad structure. Then I clean it up properly. Same behavior. Same output. Much better code using services, interfaces, and dependency injection. It shows why Copilot is powerful, but dangerous without rules. Watch the video here 👇 Enjoy the breakdown...

video preview

Hey friend, I just released a new video and I think you’ll enjoy it. In the video, I ask GitHub Copilot to build a .NET Web API using a short, vague prompt. The result works, but the structure feels random and messy. Then I run the same idea again with a stronger prompt that forces a clean structure. Feature folders. Vertical slice. Mediator. Fluent Validation. The difference is night and day. Watch the video here 👇 Enjoy the breakdown and let me know what you think. Take care, Patrick P.S....

video preview

Hey friend, I just released a new video showing a better way to use GitHub Copilot in real .NET projects. Watch it here 👇 If you ever felt like Copilot starts strong but then your code slowly turns into chaos, you’re not alone. It happens to most developers when they start using AI without giving it the right guidance. In the video, I show you one simple file you can add to your project that keeps your code clean, structured, and consistent. No guessing. No random patterns. Just a clear...