Shows how to easily create a YouTube Search page using the YouTube RESTful API and a simple DataList control.
YouTube is a popular video sharing website where users can upload, view and share video clips. YouTube was created in mid February 2005 by three former PayPal employees. The San Bruno-based service uses Adobe Flash technology to display a wide variety of video content, including movie clips, TV clips and music videos, as well as amateur content such as videoblogging and short original videos. In October 2006, Google Inc. announced that it had reached a deal to acquire the company for US$1.65 billion in Google stock. The deal closed on November 13, 2006.
Since YouTube has become so popular, it occured to me that I might want to add a YouTube Search Page to my "playground site", IttyUrl.net. It turned out that with the REST - based YouTube developer API, it was a "piece of cake".
Here is how you can add a very simple yet effective YouTube search page to your ASP.NET web site:
1) First, you need to get a free Developer Key: http://youtube.com/signup?next=/my_profile_dev. This is required to use the API. When you've got your developerKey, put it in the developerKey appSettings element in the web.config.
2) Next you will construct a REST call to the youtube.videos.list_by_tag method, passing the tag (search phrase), your developer key, and paging information.
A fully constructed dynamic REST uri would be constructed like this:
3) Since the results are returned as an XML document, there is no need to get involved in a lot of XPATH - simply load the XML into a DataSet using its ReadXml method.
4) The table that holds the information you need is DataSet.Tables - the third table in the resulting dataset.
5) I inserted some rows with my own Google Adsense ad to show how easy it is to add advertising to the resultset.
6) Bind the DataTable to a templated DataList - you are done!
Here is the complete codebehind for the search page: