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, Last week, I tested GPT-5 Agent Mode on .NET and Blazor apps, and the results were surprising. This week, I went a step further. I used GitHub Copilot inside Visual Studio and asked it to create real .NET and Blazor projects for me. Here’s what happened: Copilot generated a working calculator app in C#. It built a Web API that responded with “Hello GPT-5 Agents.” It even created a Blazor app with extra features like a reset button, a plus five counter, and a weather API. Were...
Hey Reader, I just published a new video where I put GPT-5’s Agent Mode to the test. 🚀 Instead of asking it for something simple, I went all in: A .NET 9 console app calculator A Web API with endpoints and docs A Blazor Server app with extra counter buttons And even a Blazor app that calls a public weather API 🎥 Watch it now: In the video, I didn’t just type “make me an app” and hope for the best. I gave GPT-5 very specific prompts, like: “Please create a .NET 9 console application that works...
Hey Reader, I’m back! 🎉 I’ve been on parental leave for the past 2 months, enjoying time with the family. Now I’m diving back into videos and here’s the first one! 🎥 Watch it now: Here’s the TL;DR if you can’t click right now: AI can already write code, fix bugs, and explain complex concepts. So… are we doomed? No. AI isn’t replacing developers anytime soon. But: Developers who use AI will replace those who don’t. The best devs are using GPT to: Skip repetitive work Prototype faster Learn...