views:

20

answers:

1

I'm trying to use the google search API services in the backend using C#. I know there is ajax api that you can use with javascript. so what is the similar thing in C# so I can use it at the backend level.

I know that I can do it this way:

var searchTerm = "Paris";
var web = new WebClient();

web.Headers.Add("Referrer", "http://localhost:49360/");
var result = web.DownloadString(String.Format(
                "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={0}",
                searchTerm));
Console.WriteLine(result);

but it doesn't give me any flexibility. e.x how can I set a site restriction and specify the search catagory?? e.x I want to be able to search news and finance articles for the term "Microsoft" from the CNN website only and store the urls in text file. How can I do that?? please let me know, I have been struggling for many days looking it up online and I'm getting very frustrated. thanks a lot,

+1  A: 

You have to postprocess the results from the Google AJAX Search API using a C# JSON implementation - there is advice on how to do that here.

Steve Townsend
thanks, but my question is how can I set some search settings like site restriction and search catagory. It looks like I only can specify the query string and that is it. thanks again,
Abdul Salama
Not at all - see the info here for finer grain control of your searches - http://code.google.com/apis/ajaxsearch/documentation/#SearchControlModes
Steve Townsend
but that's in JavaScript, is there a way to do the same thing in C#?? thanks,
Abdul Salama
You might be able to use something like this - http://tiredblogger.wordpress.com/2007/10/30/creating-a-google-ajax-search-control-in-net/ - this is for Web front end though, not sure of your context. If you are not using Web front end you might be able to build the required SearchControl object via JSON.Net but not sure how you would link it into the code you have above.
Steve Townsend