<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stubbleblog &#187; python</title>
	<atom:link href="http://www.stubbleblog.com/index.php/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stubbleblog.com</link>
	<description>Social Software Enthusiast</description>
	<lastBuildDate>Mon, 09 Aug 2010 21:03:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>YouTube API How-To</title>
		<link>http://www.stubbleblog.com/index.php/2006/11/youtube-api-how/</link>
		<comments>http://www.stubbleblog.com/index.php/2006/11/youtube-api-how/#comments</comments>
		<pubDate>Wed, 08 Nov 2006 22:46:57 +0000</pubDate>
		<dc:creator>Tony Stubblebine</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.stubbleblog.com/wp/?p=134</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<h2>What is it</h2>
<p>The <a href="http://www.youtube.com/dev">YouTube API</a> lets you search for videos and display them on your site. For example, I use the API to pull videos tagged dance and display them on <a href="http://www.ratemydancemoves.com">Rate My Dance Moves</a>. The YouTube API is currently the 10th most popular API on ProgrammableWeb with <a href="http://www.programmableweb.com/api/YouTube/mashups">46 mashups</a>.</p>
<p>To get started you need to sign up for a <a href="http://www.youtube.com/signup?next=my_profile_dev">developer account</a>. That will give you the developer id required to use the API.</p>
<h2>Using the API</h2>
<p>The major API methods are for retrieving lists of videos, which you can do by <a href="http://www.youtube.com/dev_api_ref?m=youtube.videos.list_by_tag">tag</a>, <a href="http://www.youtube.com/dev_api_ref?m=youtube.videos.list_by_user">user</a>, <a href="http://www.youtube.com/dev_api_ref?m=youtube.users.list_favorite_videos">user favorites</a>, and <a href="http://www.youtube.com/dev_api_ref?m=youtube.videos.list_featured">featured</a>. The information returned from the list methods is usually enough to display a video on your site. All you have to do is plug the video id into the web snippit below.</p>
<pre>
<code>
&lt;object width="425" height="350">
&lt;param name="movie" value="http://www.youtube.com/v/<strong>ID</strong>&#038;autoplay=1">
&lt;/param>
&lt;embed src="http://www.youtube.com/v/<strong>ID</strong>&#038;autoplay=1"
type="application/x-shockwave-flash" width="425" height="350">&lt;/embed>
&lt;/object>
</code>
</pre>
<p>Most of the information you need is in the video list methods. However, if you want a list of comments or channels for the video you&#8217;ll need to call the <a href="http://www.youtube.com/dev_api_ref?m=youtube.videos.get_details">get_details</a> method.</p>
<p>One complaint I had with <code>list_by_tag</code> is that the results come back ordered by relevance rather than recency. That means if you want to build a self-updating site you need to either regularly crawl the entire result set (results are paged) or sit on one of the  <a href="http://www.youtube.com/dev_api_ref?m=youtube.videos.list_by_tag">RSS Feeds.</a></p>
<h2>API Wrappers</h2>
<p>There are good libraries  for using the YouTube API with Perl, Ruby, and .NET. If you&#8217;re using another language, say Java, PHP or Python, you&#8217;ll have to write some code yourself. I&#8217;ve included links to example PHP and Python code and listed an example Ruby program that you can use as a template for whatever language you&#8217;re writing in.</p>
<p>There&#8217;s two competing Perl modules, but Hironori Yoshida&#8217;s <a href="http://search.cpan.org/author/YOSHIDA/WebService-YouTube-0.04/lib/WebService/YouTube.pm">WebService::YouTube </a> and <a href="http://search.cpan.org/author/YOSHIDA/WebService-YouTube-0.04/lib/WebService/YouTube/Feeds.pm">WebService::Youtube::Feeds </a> seem best based on the recent development activity and strength of documentation. His is the only wrapper which includes support for the feeds, nice since the feeds have functionality thats not in the API (namely list by recency).</p>
<p>Shane Vitarana released a <a href="http://shanesbrain.net/articles/2006/09/28/a-ruby-interface-to-the-youtube-api">YouTube Ruby Gem</a> after I&#8217;d built RateMyDanceMoves. Too bad, since it seems like the most polished of all the wrappers.</p>
<p>Eamonn Flynn has a <a href="http://www.eamonnflynn.net/YouTubeDotNet/YouTubeApi.htm">.NET wrapper for the YouTube API.</a></p>
<p>There doesn&#8217;t seem to be a packaged PHP library but these two tutorials from waxjelly should be enough to get you started. <br />
<a href="http://www.waxjelly.com/2006/08/28/simple-php-script-using-the-youtube-api-with-pagination-part-1/">Simple PHP Script Using the YouTube API with Pagination</a><br />
<a href="http://www.waxjelly.com/2006/08/29/a-more-complex-php-script-using-the-youtube-api-with-video-details-part-2/">A More Complex PHP Script Using the YouTube API with Pagination.</a></p>
<p>ThinkHole labs has some <a href="http://thinkhole.org/wp/2006/01/09/the-youtube-api-and-python/">example YouTube API code for Python users</a>. Apparently using the API can be as simple as passing a dictionary to YouTube&#8217;s XML-RPC interface.</p>
<h2>Code Example</h2>
<p>I&#8217;d written my own code before the Ruby library came out. I want to show it here so you can see how simple writing your own code would be.</p>
<p><pre>
<code>
#!/usr/bin/env ruby
require 'open-uri'

tag = "dancing"
per_page = "100"
def_id = "YOUR_DEV_ID_HERE"
url = "http://www.youtube.com/api2_rest?" \
+ "method=youtube.videos.list_by_tag" \
+ "&#038;tag=#{tag}&#038;per_page=#{per_page}&#038;dev_id=#{dev_id}&#038;page=1"

open(url) do |f|
xml = f.read
end

doc = REXML::Document.new(xml)

elements = doc.root.get_elements("//video")
elements.each do |v|
puts v.get_elements("id").first.get_text.to_s
puts v.get_elements("title").first.get_text.to_s
puts v.get_elements("tags").first.get_text.to_s
puts v.get_elements("thumbnail_url").first.get_text.to_s
end
</code>
</pre>
</p>
<h2>More Info</h2>
<p><a href="http://www.quickonlinetips.com/archives/2006/10/the-amazing-youtube-tools-collection">The Amazing YouTube Tools Collection</a> has a long collection of YouTube tools, mashups, and plugins. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.stubbleblog.com/index.php/2006/11/youtube-api-how/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
