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


.NET Web Academy

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

Read more from .NET Web Academy

Hey friend, The other day I found a bug in StackBuddy, an app I built. Normally I'd open it, file a ticket for myself, and move on. Instead I turned to my AI and just said, "log a dev ticket for that." And it did. A real ticket in my own bug tracker. Title, description, priority, the whole thing. I never opened the actual app. The thing that makes that possible is called MCP, Model Context Protocol. Ignore the name for a second. Out of the box, an AI can only talk. It writes and explains, but...

Hey friend, I don't really write code by hand anymore. I describe what I want, and the AI builds it. For a while, that scared me. If I am not writing the code, does everything I spent years learning still matter? Does my stack matter at all? If you are a developer right now, I would bet you have felt some version of that too. Here is where I landed. It flipped the whole thing for me. The other day I was debugging a slow app, talking it through with the AI. Would WebAssembly help here? Is it...

video preview

Hey friend, Lately I told an AI I’d see it in 7 hours, and went to bed. It was done in 2. Across two different projects. There’s this thing people call the night shift. You give an AI agent a pile of work, start it in a loop, and go to sleep while it keeps working on your real codebase. I tried it a month ago and could not make it work, the model just fell apart. But with the newest models, it works now. And the surprising part wasn’t that it ran all night. It’s that it ran out of work before...