<?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>firsttube.com &#187; API</title>
	<atom:link href="http://www.firsttube.com/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.firsttube.com</link>
	<description>crunchy nuggets, served semi-daily</description>
	<lastBuildDate>Tue, 03 Jan 2012 00:14:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PHP Weirdness</title>
		<link>http://www.firsttube.com/read/php-weirdness/</link>
		<comments>http://www.firsttube.com/read/php-weirdness/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 19:46:03 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Yahoo!]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=660</guid>
		<description><![CDATA[Beware: this post is definitely not for the feint of heart. It includes a lot of code. You have been warned. I wrote an application some time ago for my company that looks up the longitude and latitude of an &#8230; <a href="http://www.firsttube.com/read/php-weirdness/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Beware: this post is definitely not for the feint of heart.  It includes a lot of code.  You have been warned.</p>
<p>I wrote an application some time ago for my company that looks up the longitude and latitude of an address for use in our geocoding initiative.  It relied on yahoo_geo(), <a href="http://toys.lerdorf.com/archives/2005/11.html">a function written by PHP creator Rasmus Lerdorf</a> and the Yahoo Maps API.  It was largely dependent on this function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> yahoo_geo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&amp;amp;location='</span>
		<span style="color: #339933;">.</span><span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/tmp/yws_geo_'</span><span style="color: #339933;">.</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	request_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmp</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">43200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">libxml_use_internal_errors</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Result<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Result<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>children<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>This function worked for over two years for us with no problems at all.  Then suddenly, in the last month, it started getting spotty.  I fixed things by commenting out the caching parts of the function and forcing each execution to run again.  Then I got errors about the libxml_use_internal_errors() function, so I commented that out.  But today, the function just flat out failed, every single time returning the same error: </p>
<p><strong>Warning: file_get_contents(http://XXXXXXXXXX/XXX) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/intranet/html/fetch.php on line X</strong></p>
<p>What the heck? This code is all over the web.  I&#8217;ve tried a million permutations of this function, including using fopen() and ob_get_contents(), and none have worked.  And most frustratingly, I could load the URL successfully in Lynx and eLinks, so the machine could quickly and easily fetch the URL.</p>
<p>So I ventured into a sandbox I&#8217;ve never really played before: <a href="http://us2.php.net/manual/en/ref.curl.php">cURL</a>.   cURL is an interesting animal.  But the interesting thing is, once I got it working, it worked faster than ever! So, without further ado, here is the new and improved yahoo_geo() function: </p>
<p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> yahoo_geo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&amp;#038;location='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p><small><strong>Note:</strong> If you&#8217;re reproducing these functions elsewhere, be careful &#8211; WordPress may have converted the quotes into smart quotes that will need to be fixed before this script will run properly. </small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/php-weirdness/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flickr Feeds</title>
		<link>http://www.firsttube.com/read/Flickr-Feeds/</link>
		<comments>http://www.firsttube.com/read/Flickr-Feeds/#comments</comments>
		<pubDate>Mon, 11 Dec 2006 15:25:22 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Flickr]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/Flickr-Feeds</guid>
		<description><![CDATA[Who knew that Flickr supported so many types of feeds? RSS, RDF, Atom, SQL, PHP, Serialized PHP, YAML, CSV, JSON, CDF&#8230; that&#8217;s incredible.]]></description>
			<content:encoded><![CDATA[<p>Who knew that <a href="http://www.flickr.com/services/feeds/">Flickr supported so many types of feeds</a>? RSS, RDF, Atom, SQL, PHP, Serialized PHP, YAML, CSV, JSON, CDF&#8230; that&#8217;s incredible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/Flickr-Feeds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Dream App More Like A Nightmare</title>
		<link>http://www.firsttube.com/read/My-Dream-App-More-Like-A-Nightmare/</link>
		<comments>http://www.firsttube.com/read/My-Dream-App-More-Like-A-Nightmare/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 14:33:33 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Applications]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[My Dream App]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/My-Dream-App-More-Like-A-Nightmare</guid>
		<description><![CDATA[So, awhile back, someone came up with this idea &#8211; invite users to dream up an application, then hold a contest and actually develop the best ones. I mean &#8211; how cool is that, right? ANYTHING you can think of! &#8230; <a href="http://www.firsttube.com/read/My-Dream-App-More-Like-A-Nightmare/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, awhile back, someone came up with this idea &#8211; invite users to dream up an application, then hold a contest and actually develop the best ones.  I mean &#8211; how cool is that, right? ANYTHING you can think of!  What a great opportunity to see some incredible ideas come to life.  </p>
<p>Let me cut to the chase: <a href="http://arstechnica.com/journals/apple.ars/2006/10/26/5768">it appears the vote has been hacked</a>.  Clearly, something fishy is going on here! </p>
<p>The winners are &#8211; get this &#8211; a cookbook, a sync manager, and a thing that makes your desktop look like the weather.  I cannot believe it.  I&#8217;m stunned.  THIS is what Mac users wanted? THIS is the best we could come up with? </p>
<p>One guy dreamt big: you hum into your computer and it pitch corrects and allows you to create a song.  Whoa! Cool! </p>
<p>One girl had an interesting idea: you take pictures of your clothes and then can keep a &#8220;virtual closet&#8221; where you can look at your clothes together and design outfits.&#8221;  Holy crap &#8211; NOTHING I know of does this, even if I don&#8217;t have much of a need for it. </p>
<p>But you see, these are REAL apps that are the first of their kind.  Who needs a new sync manager? And who but chefs will really use Cookbook?  And I couldn&#8217;t care less about my desktop wallpaper matching the weather, being as though I can LOOK OUTSIDE if I want to know! </p>
<p>What a letdown. </p>
<p><a href="http://arstechnica.com/journals/apple.ars/2006/10/26/5768">Read More</a> | <a href="http://digg.com/apple/Controversy_surrounds_My_Dream_App_Voter_fraud">Digg Story</a></p>
<p><small>received via the <a href='http://firsttube.com'>firsttube.com</a> API</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/My-Dream-App-More-Like-A-Nightmare/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>firsttube.com Now Has An API</title>
		<link>http://www.firsttube.com/read/firsttubecom-Now-Has-An-API/</link>
		<comments>http://www.firsttube.com/read/firsttubecom-Now-Has-An-API/#comments</comments>
		<pubDate>Thu, 12 Oct 2006 10:56:42 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Digg]]></category>
		<category><![CDATA[OSNews]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/firsttubecom-Now-Has-An-API</guid>
		<description><![CDATA[Well, something I&#8217;ve LONG considered implementing is an API for my website. Yes, there&#8217;s VERY little to ever use an API for me, however, it&#8217;s always been one of those &#8220;out there&#8221; challenges. It&#8217;s always been breaking new ground to &#8230; <a href="http://www.firsttube.com/read/firsttubecom-Now-Has-An-API/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Well, something I&#8217;ve LONG considered implementing is an API for my website.  Yes, there&#8217;s VERY little to ever use an API for me, however, it&#8217;s always been one of those &#8220;out there&#8221; challenges.  It&#8217;s always been breaking new ground to parse an XML request and return XML to it.  I&#8217;ve tried probably 10 times before, and each time I&#8217;ve given up.  This time, I had to figure it out. </p>
<p>So I slammed the pedal to the metal and did it.  I now have a working API.  It currently supports only 1 method reliably &#8211; blogger2.newPost() &#8211; however, I have tested blogger.getRecentPosts and both corresponding methods under the metaWeblog API.   That said, I will probably hack something up that explains how to add an API to your homegrown PHP weblog.  There are functions out there that do the hardwork, and there are functions I&#8217;ve written that do the rest of the work, so you just need to write the correct queries for your database. </p>
<p>Anyway, I can now post from digg.com, which is cool.  Ultimately, if we ever support user blogs on OSNews, we&#8217;ll roll out an API so people can comment on <a href='http://osnews.com'>OSNews</a> and Digg stories via the API.  Could be interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/firsttubecom-Now-Has-An-API/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

