Jerry Nixon on Windows: Easily use Bing’s REST API v2 to get Search Data in your Metro App

Jerry Nixon's blog

Wednesday, June 13, 2012

Easily use Bing’s REST API v2 to get Search Data in your Metro App

imageMicrosoft Bing Search has a set of free, exposed REST APIs that has been very popular. It allows you to do a series of queries. But let me let the documentation do the talking:

Bing API Version 2.0 enables you to embed a flexible and powerful search engine as a custom search component in your sites and applications. The new version includes:

  • HTTP endpoints with results in XML or JSON
  • Enhanced support for SOAP
  • A fully OpenSearch compliant RSS interface

Something you should know

If you are anxious to port your Windows Phone application using the Bing API, you should know that they will be discontinued on August 1, 2012. At that time, they will be ported from Bing to the Azure Data Marketplace. We’ll talk about that in a later article.

imageFirst, get a key

So, herein lies the rub. If you are not already using the Bing API v2.0 then you cannot get a new developer token. This is important because it is about to be discontinued.

However, in an effort to facilitate developers porting their Windows Phone applications using the Bing API over to Metro applications, I hope this gives you a head start.

See what I mean here.

Second: copy my BingV2Helper

Another in a series of helpers, the Bing V1 Helper makes the REST call for you and deserializes the resulting JSON into CLR classes for you. Yelp, it’s that easy. My helper can get you started, you can extend it. Or just learn from what I have done.

Get the code here.

Here’s Helper’s API looks like this:

Constructor(s)


BingApiV2Helper(key);

Example:

var _Helper = new BingApiV2Helper(“youneedyourownkey”);

Method(s)

SearchAsync(query, type);

Example:
var _Results = SearchAsync(“coffee”, SearchTypes.Web);

I don’t want to oversimplify it, but the API is simple to begin with. The helper is meant to do the hard work for you so you can add it to your projects easily and just start using. If you are already using the Bing API, then this will be a nice treat for you.

Conclusion

It is important that you remember that this API will not live forever. In fact, it will be discontinued August 1, 2012. At that time you should migrate to the Azure Data Marketplace’s Bing API. It is no longer free, but there is a free tier so you can still use it in your applications.

Best of luck!