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.
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.
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
Become a .NET & Blazor expert with weekly tutorials featuring best practices and the latest improvements, right in your inbox.
Hey Reader, .NET 10 just dropped. 🥳 And if you’ve been waiting for a reason to build something new, this is it. In my latest tutorial, I’ll walk you through how to build a complete Web API from scratch in .NET 10, including: Setting up Controllers Using Entity Framework Core 10 Connecting SQL Server Working with DTOs the right way It’s perfect if you’re starting fresh or want to upgrade an older .NET 8 or .NET 9 project to the newest version. Watch the full tutorial here 👇 Take a look, and...
Hey Reader, .NET 10 is almost here, and it brings a big upgrade for validation in Minimal APIs. In this week’s tutorial, I’ll walk you through how validation works now in .NET 10 (using Entity Framework, Scalar, and Minimal APIs). Before, writing validation logic in each endpoint was a pain. You had to manually check for null values, invalid quantities, or missing fields. But in .NET 10, that’s all built-in and super clean. Watch the full tutorial now: 👇 Happy coding! Take care, Patrick
Hey Reader, If you’ve been coding for a while, you’ve probably asked yourself this too: “Am I getting better… or just older?” I’ve been writing software for fifteen years now, and that question still sneaks up on me. But looking back, I’ve realized something: real growth in tech isn’t about frameworks or chasing trends. It’s about staying curious, patient, and keeping your spark alive when everything feels heavy. So I made a new video about it, my 15 biggest lessons from 15 years of coding....