18 January 2012 You Tube API CI Team

image.png

 

A loooong time ago I’ve blogged about how to access to You Tube with the Google Data APIs. After all that time there are several new ways how to recall files. Google offers You Tube a “simple” surface. If you prefer to do low-Level HTTP calls it is also possible.

Aim: I want the files to this You Tube video – but I already have the URL:

http://www.youtube.com/watch?v=ItqQ2EZziB8 (different to my former Blogpost where I was searching stuff)

download the library with NuGet

For comfortable excess I recommend you Google Data APIs. You will find this on NuGet as well:

All you need is the Google.GData.Client and the Google.GData.YouTube package:

image

Code

(because my Testclient is a console application and I need the functionality from the System.Web Assembly I changed the whole Frameworkt to .NET 4.0)

Uri youTubeLink = new Uri("http://www.youtube.com/watch?v=ItqQ2EZziB8");
            var parameters = System.Web.HttpUtility.ParseQueryString(youTubeLink.Query);
            var videoId = parameters["v"];

            Uri youTubeApi = new Uri(string.Format("http://gdata.youtube.com/feeds/api/videos/{0}", videoId));
            YouTubeRequestSettings settings = new YouTubeRequestSettings(null, null);

            YouTubeRequest request = new YouTubeRequest(settings);
            var result = request.Retrieve<Video>(youTubeApi);

            Console.WriteLine(result.Title);
            Console.WriteLine(result.Description);
            Console.WriteLine(result.ViewCount);

            Console.ReadLine();

Declaration

In line 3 I take the “v” parameter for the video. In line 5 I apply empty YouTubeRequestSettings – with this I’m able to call every official service but I can’t leave comments or upload videos.

Afterwards the Video will be picked up with the request.Retrieve. Now I have several Meta information’s about the Video.

No “Retrive” Method?

During the development process I’ve recognized a strange problem – under the Request-Object I had no Retrieve or Get Method. I’m not sure what the problem is. At least the You Tube Request class is from the Google.YouTube namespace – maybe I got the wrong class.

More Informations on the YouTube API.NET side.

Result of my codes:

image

[Code on Google Code]