Retrieve and Update YouTube Content in C#


The YouTube Google API for .NET developers can be used in C# or ASP.NET applications to authenticate a YouTube user, to extract information about a single video from a list of videos or a set of search results, to fetch a list of videos, to upload videos to YouTube, to interact with YouTube videos, to access, create and update favorite videos, and to subscribe to YouTube channels.

Example 1. Authenticating a YouTube User

YouTubeRequestSettings settings = new YouTubeRequestSettings(“example app”, clientID, developerKey);
YouTubeRequest request = new YouTubeRequest(settings);

Example 2.Displaying a Feed of Videos

Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
static void printVideoFeed(Feed<Video> feed)
foreach (Video entry in feed.Entries)

Example 3. Searching YouTube Videos

YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
//order results by the number of views (most viewed first)
query.OrderBy = “viewCount”;
// search for puppies and include restricted content in the search results
// query.SafeSearch could also be set to YouTubeQuery.SafeSearchValues.Moderate
query.Query = “C# Learners”;
query.SafeSearch = YouTubeQuery.SafeSearchValues.None;
Feed<Video> videoFeed = request.Get<Video>(query);

Example 4. Uploading Videos to YouTube

Video newVideo = new Video();
newVideo.Title =”Serialization”;
newVideo.Tags.Add(new MediaCategory(“Autos”, YouTubeNameTable.CategorySchema));
newVideo.Keywords = “Programming, C#”;
newVideo.Description = “This video explains how to use Serialization in C#”;
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory(“mydevtag, anotherdevtag”,
newVideo.YouTubeEntry.setYouTubeExtension(“location”, “Vancouver, BC”);
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(“c:\\”,
Video createdVideo = request.Upload(newVideo);

Example 5. Adding a Favorite Video to YouTube

YouTube users can choose to mark videos that they watch as favorite videos. A user’s favorite videos feed can be retrieved from the following URL:

To add a favorite video, insert a YouTubeEntry object that identifies the video to the authenticated user’s favorite videos feed:

string videoEntryUrl = “”;
YouTubeEntry videoEntry = (YouTubeEntry) service.Get(videoEntryUrl);
service.Insert(new Uri(feedUrl), videoEntry);

Copyright © All Rights Reserved - C# Learners