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 friend, Working from home as a .NET developer sounds great. Freedom. No meetings. Full control. But after a while, it gets heavy. You make every decision alone. Architecture. Azure. Refactoring. Deployment. And sometimes you just want someone to say, โYeah, thatโs fine. Ship it.โ AI helps. Tutorials help. But real conversations with other developers hit different. In today's video, I talk about why working alone can slow us down and why feedback from other devs matters more than we think....
Hey friend, Quick one today. GitHub Copilot makes form validation feel easy. But if you are not careful, it slowly decides where your logic lives. Your app still works. But the structure gets worse. In today's video, I show you: A simple Blazor register form How Copilot refactors it the wrong way How to move validation out cleanly How to guide Copilot with clear rules Watch the video here ๐ Have a great start to the new year! ๐ Take care, Patrick P.S. If you want to learn how to use AI as a...
Hey friend, I just released a new video and wanted to share it with you. Watch the video here ๐ I used GitHub Copilot to build a small Blazor weather app. It worked almost instantly and even used real API calls. At first glance, everything looked great. Then I opened the Razor file. All the logic was sitting in one place. UI, API calls, and business logic mixed together. It worked, but it was not something I would ship. In the video, I show how I fix this using a single refactoring prompt. I...