Processing Yahoo Search Library
8 Comments Published August 5th, 2007 in API, blog, book, java, library, p5, processing.org, yahoo
Now, I am rather overdue for an update on my upcoming book. I’ll be posting details soon. However, in the course of finishing up a chapter on String parsing, I discovered that my good friend, the Google SOAP API is no longer being supported (obviously, I’m a little late on the ball here.)
So, I quickly whipped up a Processing library to make use of the Yahoo Search API. Now, you can access the Yahoo! API directly in Processing. There’s even an example here. However, you would have to write your own thread if you wanted to search asynchronously. In addition, if you’re not comfortable diving into outside Java APIs, you might struggle to figure out the syntax. (Switchboard also provides an interface to the Yahoo! API.)
So I set out (as an example for my book) to make a quick and easy bridge to the Yahoo API.
Finally, take a peek at this example code.
// Import the library
import pyahoo.*;
YahooSearch yahoo;
void setup() {
size(400,400);
// Make a search object
yahoo = new YahooSearch(this,"YOUR API KEY HERE");
}
void mousePressed() {
yahoo.search("processing.org");
// You can request more results like so (the default is 10):
// yahoo.search("processing.org",30);
}
void draw() {
noLoop();
}
// The searches will come in one at a time to here when finished
void searchEvent(YahooSearch yahoo) {
// You can get the titles, URLs, or Summaries back as an array of Strings
String[] titles = yahoo.getTitles();
String[] urls = yahoo.getUrls();
println("\nI searched for " + yahoo.getSearchString());
println("There are a total of " + yahoo.getTotalResultsAvailable() + " results available");
println("Here are the first " + yahoo.getNumberRequested());
for (int i = 0; i < titles.length; i++) {
println("___________");
println("Item # " + i);
println(titles[i]);
println(urls[i]);
}
// You can also access the Yahoo API Directly by asking for the WebSearchResult object:
// WebSearchResults results = yahoo.getResults();
// WebSearchResult[] results = yahoo.getResultsArray();
// In this mode, make sure to import the Yahoo library up topl
// import com.yahoo.search.WebSearchResults;
// See Yahoo API documentation for more
}
There's also a fancier example (mostly uncommented, sorry) that produced the image at the top of this post here.
Thoughts? Helpful? Useful?
8 Responses to “Processing Yahoo Search Library”
- 1 Pingback on Nov 15th, 2008 at 6:29 pm
haven’t tried it yet but it looks cool!
Hey Daniel,
I am wondering why you are using both “System.out.println” and “println” in the same example. Can’t you just use “println” all the time? … or do you know something I don’t?
– David Jones
Ooops, that’s just an error. Yes, in Processing all you need is “println()”.
I downloaded the SDK, however i cannot locate any .jar file like it said.
Searched google for it, only came back with this site
Any heads up on that?
Thanks..
P.S. Great information here. Good job man!
you have to go to the java project folder of the sdk and type ant. it will build the stuff in a build folder. you can get the jar from build/pkg
cheers
Thanks for the great library, however we have problems to find the .jar file in the sdk. What do you mean by “…type ant.” ?????
cheers
This is the SDK you need:
http://sourceforge.net/projects/jyahoosearchsdk/
Not the regular Yahoo SDK. You won’t find the .jar in that download.