Introduction
YouTube is firmly entrenched in our lives. Now, many users cannot imagine life without the use of this site. Due to the simplicity and ease of use, YouTube has become the most popular video sharing and one of the most popular websites in the world. Like many popular Google services, YouTube has Data API. This API allows you to interact with this service. This opens up great opportunities for developers of sites and various applications. Using this API, developers can query videos, search videos, upload videos on YouTube, create and read reviews and more.
Problem
Our goal is to query all the videos from YouTube channel of the famous Russian DJ and show them on the website.
Solution of the Problem
To work with YouTube Data API, you need to download and install the Google Data API library. Then copy Google.GData.Client.dll, Google.GData.YouTube.dll, Google.GData.Extensions.dll files into the Bin folder of the website project and add references to them. How to do this was described in detail in my other article, Using Google Calendar in an ASP.NET website.
To use all possibilities that YouTube Data API offered, you need to get Developer Key.
Developer key uniquely identifies an application that will interact with the YouTube service. You can get it here.
Let’s create a class to represent YouTube video on our site. The object of this class is a video that has properties: VideoId and Title.
VideoId represents unique identifier for the video on YouTube and Title is the title of the video on YouTube:
public class YouTubeVideoObject
{
public string VideoId { get; set; }
public string Title { get; set; }
}
Let’s create a class that will interact with YouTube, and return us all the videos (objects of YouTubeVideoObject class) of channel:
public class YouTubeVideoHelper
{
const string YOUTUBE_CHANNEL = "BobinaMusic";
const string YOUTUBE_DEVELOPER_KEY = "AI39si6JqO_f2b_JWSV3QUbcwg5S-1RJ4-
kiieosBZy9r1ORkCAv7BT5tLp579Tzmly8rvOVm3Jyueq3ZVqUNt1blS4DcoVppA";
public static YouTubeVideoObject[] GetVideos()
{
YouTubeRequestSettings settings =
new YouTubeRequestSettings("Bobina Channel", YOUTUBE_DEVELOPER_KEY);
YouTubeRequest request = new YouTubeRequest(settings);
string feedUrl = String.Format
(,
YOUTUBE_CHANNEL);
Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
return (from video in videoFeed.Entries
select new YouTubeVideoObject()
{VideoId = video.VideoId, Title = video.Title}).ToArray();
}
}
Description of Constants
YOTUBE_CHANNEL - Channel from which we will show videos
YOUTUBE_DEVELOPER_KEY - Developer key, obtained in step 2
Read more: Codeproject
1 comments:
Everything is very open with a really clear
description of the issues. It was really informative.
Your website is very helpful. Thank you for sharing!
Feel free to surf to my homepage - castleville
Post a Comment