Google Search API vs Bing Search API

Oct 3 2011 5:30 PM OCT 3 2011 5:30 PM
Search Engine APIPHP | JSON | Web Services

One of the things I love to do is learning various API's and new technologies. One of my many side projects is a Dance Dictionary that will contain step names, how to's, definitions, videos and pictures. I started writing up the tech specs and a scope for the project and start to think about utilizing a search engine to power parts of it.

Out of my research the two engines that came to mind were Google and Bing. Now my scope of the project will rely heavily on two things. 1) Images 2) Videos. Later on ill probably utilize more items such as question and answers and such but that cant wait.

Google Search API

Google tends to be rather difficult to work with. While they hold the majority of the market they tend to deprecate their API faster than they can to develop new ones. They have a Image API, but it is currently deprecated and has "soft caps" on it limiting the usage behind it. Because of this I am looking at other options Google offers.

So a few of their API's I looked into but had very little luck. With not being able to use the image API because its deprecated I quickly found myself moving on to other possibilities. One of my ideas was to even cURL:

 

http://www.google.com/search?tbm=isch&q=Ballet+Cambre

This will query the Google Image Results page and give you results based on your search. From their I would then proceeded to use the Simple DOM element.

$dom = new DOMDocument;
$dom->loadHTML($str);

From that I can easily grab all the images on the result page. However, if Google changes the way they display the results by running a ajax call after the page loads or something along these lines I might as well throw this whole lot out the door. Other options do exist here but involve using their web search API and that doesn't allow searching the image section currently. The old Image API is no longer supported by them and there is no telling how long it will stick around. With that their isn't very much ability or reliability with Google here...

Bing Search API

Now to my surprise I found Bing to be extremely easy and very powerful. Within a total of about 5 minutes I had data pulling from a basic search query. All you need is a Windows Live Account, "You can setup with any email address." It comes with a SkyDrive "25gb free storage." which is great in comparison to how much most site store. And then set up an application to get an AppId. The id you will use when making your API calls.

In PHP you can use the following to make your calls.

class bing{
	var $appId;
	var $request_uri = "http://api.bing.net/json.aspx?";
	var $setting;
	public function __construct($id){
		$this->appId = $id;
		$this->request_uri .= "AppId=".$id;
	}
		
	function settings($args=array()){
		$this->setting = "&".implode("&", $args);
	}
		
	function call(){
		$res = file_get_contents($this->request_uri.$this->setting);
		return $res;
	}
}

Now this is relatively basic and can be expanded using cURL and a few other techniques but why go to crazy for a basic tutorial? Now to make the call...

$bing = new bing("Your App ID Here...");
$bing->settings(array("Query=".urlencode("Ballet Cambre"), "Sources=Image"));
echo "<pre>".print_r(json_decode($bing->call()), true)."</pre>";

As you can see its really basic and simple! There API allows you to do a wider range of things than listed above. To add additional arguments you simple append more to the array. 

Concluding

While Google does hold a lot of power they tend to fail in documenting their API's and search ability via an API or other solution. Bing on the other hand offers a very well documented straight forward usage of their API. As I showed above I literally spent all of maybe 5-10 minutes working through a decent solution with them. While I don't care for the fact Bing is a Microsoft product, I have to say so far its proven to be very well versed and thought out. Google is starting to really show that having everything and being everything is not the best idea. They may be one of the largest companies online, but making a long lasting stance they will need to pick up the pace on being clearer.