
<?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>daniel shiffman &#187; API</title>
	<atom:link href="http://www.shiffman.net/category/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shiffman.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2012 03:41:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Processing Yahoo Search Library</title>
		<link>http://www.shiffman.net/2007/08/05/processing-yahoo-search-library/</link>
		<comments>http://www.shiffman.net/2007/08/05/processing-yahoo-search-library/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 02:51:22 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[p5]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.shiffman.net/2007/08/05/processing-yahoo-search-library/</guid>
		<description><![CDATA[2011 Update: While this library may still work, I am deprecating it as Yahoo does not support the Java Search API any longer as far as I can tell Now, I am rather overdue for an update on my upcoming &#8230; <a href="http://www.shiffman.net/2007/08/05/processing-yahoo-search-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>2011 Update: While this library may still work, I am deprecating it as Yahoo does not support the Java Search API any longer as far as I can tell</strong></p>
<p><img src="http://www.shiffman.net/p5/pyahoo_files/names.jpg"/></p>
<p>Now, I am rather overdue for an update on <a href="http://book.shiffman.net">my upcoming book</a>.  I&#8217;ll be posting details soon.   However, in the course of finishing up a chapter on String parsing, I discovered that my good friend, the <a href="http://code.google.com/apis/soapsearch/">Google SOAP API</a> is no longer being supported (obviously, I&#8217;m a little late on the ball here.) </p>
<p>So, I quickly whipped up a <a href="http://www.processing.org">Processing</a> library to make use of the Yahoo Search API.  Now, you can access the Yahoo! API directly in Processing.  There&#8217;s <a href="http://processing.org/learning/libraries/yahoosearch.html">even an example here</a>.  However, you would have to write your own thread if you wanted to search asynchronously.  In addition, if you&#8217;re not comfortable diving into outside Java APIs, you might struggle to figure out the syntax.   (<a href="http://www.realtimeart.com/switchboard/">Switchboard</a> also provides an interface to the Yahoo! API.)</p>
<p>So I set out (as an example for my book) to make a quick and easy bridge to the Yahoo API.    </p>
<li class="arrow"><a href="http://www.shiffman.net/p5/pyahoo_files/pyahoo.zip">Download the library here</a></li>
<li class="arrow"><a href="http://developer.yahoo.com">Go and get a developer ID</a></li>
<li class="arrow"><a href="http://developer.yahoo.com/download">Download the Yahoo! Search SDK</a>  Find the file: yahoo_search-2.X.X.jar and put it in the library folder (along with the above download).</li>
<p>Finally, take a peek at this example code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Import the library</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">pyahoo.*</span><span style="color: #339933;">;</span>
&nbsp;
YahooSearch yahoo<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span>,<span style="color: #cc66cc;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Make a search object</span>
  yahoo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> YahooSearch<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>,<span style="color: #0000ff;">&quot;YOUR API KEY HERE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> mousePressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  yahoo.<span style="color: #006633;">search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;processing.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// You can request more results like so (the default is 10):</span>
  <span style="color: #666666; font-style: italic;">// yahoo.search(&quot;processing.org&quot;,30);</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  noLoop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The searches will come in one at a time to here when finished</span>
<span style="color: #000066; font-weight: bold;">void</span> searchEvent<span style="color: #009900;">&#40;</span>YahooSearch yahoo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// You can get the titles, URLs, or Summaries back as an array of Strings</span>
  <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> titles <span style="color: #339933;">=</span> yahoo.<span style="color: #006633;">getTitles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> urls <span style="color: #339933;">=</span> yahoo.<span style="color: #006633;">getUrls</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>I searched for &quot;</span> <span style="color: #339933;">+</span> yahoo.<span style="color: #006633;">getSearchString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;There are a total of &quot;</span> <span style="color: #339933;">+</span> yahoo.<span style="color: #006633;">getTotalResultsAvailable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; results available&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Here are the first &quot;</span> <span style="color: #339933;">+</span> yahoo.<span style="color: #006633;">getNumberRequested</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> titles.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;___________&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Item # &quot;</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    println<span style="color: #009900;">&#40;</span>titles<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    println<span style="color: #009900;">&#40;</span>urls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// You can also access the Yahoo API Directly by asking for the WebSearchResult object:</span>
  <span style="color: #666666; font-style: italic;">// WebSearchResults results = yahoo.getResults();</span>
  <span style="color: #666666; font-style: italic;">// WebSearchResult[] results = yahoo.getResultsArray();</span>
  <span style="color: #666666; font-style: italic;">// In this mode, make sure to import the Yahoo library up topl</span>
  <span style="color: #666666; font-style: italic;">// import com.yahoo.search.WebSearchResults;</span>
  <span style="color: #666666; font-style: italic;">// See Yahoo API documentation for more</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There&#8217;s also a fancier example (mostly uncommented, sorry) that produced the image at the top of this post <a href="http://www.shiffman.net/p5/pyahoo_files/names.zip">here</a>.  </p>
<p>Thoughts?  Helpful?  Useful?  </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shiffman.net/2007/08/05/processing-yahoo-search-library/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

