Taming the Wild Wild Web

Jul 22 2008   12:53AM GMT

More on Using APIs to Spice Up Your Web Content



Posted by: Jeffrey Olchovy
PHP, Web development, Yahoo!, API, Web services

In our last installment of Taming the Wild Wild Web, we gave a brief introduction to APIs and how they can help add user interactivity to your Web site. We also listed some big Web companies who allow developers open source access into their Application Programming Interfaces.

On a side note, the integration of select APIs into your Web site may have the potential to generate a great amount of traffic to your domain. How you ask? Well, depending upon your script, you may very well be adding tons of contextually relevant content to your site’s pages. Now remember, this is correlation and not causation. We are assuming that, say, if you were to automatically fill a section of your page with related links and blurbs from Yahoo! News that just so happen to be related to the keyword phrase you are targeting; you have essentially added quite a bit of topically relevant content to your Web site. This new, fresh and dynamically updating content will subsequently aid in your ranking on the search engine results pages. Yahoo! does however limit the queries made per day from each API key - so please - keep this in mind.

Now - enough theory - let’s put that example into practice.

First things first. Since we’ll be using Yahoo!’s Web Services API, we are going to need an API key. So go on over to their developer network, register your Web site and grab yourself your Application ID. For this example, we’ll use their demo key.

Yahoo!’s API is compatible with just about every popular server-side scripting language you can think of, but for the scope of this example, I expect that you have a working knowledge of PHP as this will be the language that we’ll be working with from herein.

The Web Services API is built upon RESTful architecture and can output data in SimpleXML, JSON or serialized PHP format (much to our convenience).

To query Yahoo!’s stored data we must construct a valid REST request. For their News Services, the request URL that will ultimately provide us with the base of our query is:
“http://search.yahooapis.com/NewsSearchService/V1/newsSearch?”

After the trailing question mark is where we will append our query parameters.

You can see all of the parameters available for each Web service at Yahoo!’s developer network. When passing these parameters, they must be in the format of ‘argument=value’ and must be URL encoded. However, the only required arguments you supply are your API key (’appid’) and the string you will pass to query their database (’query’).

With this in mind, a barebones REST request to query Yahoo!’s New Service would look something like this:

“http://search.yahooapis.com/NewsSearchService/V1/newsSearch?appid=YahooDemo&query=paul%20mccartney”

This will return the results of their News Service Database for the query “Paul McCartney” with default parameters.

In our third installment of using simple API features to spice up your Web site, we’ll implement specialized, non-default parameters in our example so that we can generate a set of custom results for our page that’s in need of some relevant content.

Jeffrey Olchovy is a Web developer, designer and marketing strategist.

Comment on this Post


You must be logged-in to post a comment. Log-in/Register