SIGN UP MEMBER LOGIN:    
ARTICLE

Intergrating with google Search API

Posted by mem_1910 Articles | Internet & Web August 17, 2006
This article will show us how to integrate with "Google Search API" from our windows application or web application.
Reader Level:

Google created a search API web service that allow us to search billions of web pages from our own applications, those web services can be exposed from any programming environment such as .Net or java.

So the following are the needed steps for integrating with this service and small .Net sample .

  1. You can download the Developers Kit which contains .net and java samples and the wsdl file from the following Url. 

    http://www.google.com/apis/download.html

  2. You must have google account 'gmail' in order to get the license key for using this API. So if you don't have an account you should go to the following link and create one. 

    https://www.google.com/accounts/NewAccount?
    continue=http://api.google.com/createkey&
    followup=http://api.google.com/createkey


    or if you already have one just sign in and an email message containing the license  key will be sent to you .

    https://www.google.com/accounts/Login?continue=http%3A%2F%2Fapi.google.com%2Fcreatekey&followup=http%3A%2F%2Fapi.google.com%2Fcreatekey

  3. After you get the license key you can start develop the application which we will mention in the following steps.

    • Open Visual Studio .Net 2003 or 2005 
    • Choose new project and select the type and your preferred language ' we will choose win app with C# in our example'
    • Right click in the solution explorer and choose add web reference and write the following url  in the appeared dialog 

      http://api.google.com/GoogleSearch.wsdl 

      And choose add reference as in the picture.



    • Put in the form a textbox and change its ID to Txt_Text for the search and put a button and change it's ID to Btn_Search 
    • Drag and drop a datagrid if you are using 2003 or datagridview if 2005 .
    • Write the following code under the Btn_Search _Click event.

      com.google.api.GoogleSearchService s = new TestGoogle.com.google.api.GoogleSearchService();
      com.google.api.GoogleSearchResult r = s.doGoogleSearch("put your lisence key her ", Txt_Text.Text, 0, 10, false, "", true, "", "", "");
      int estimatedCount =r.estimatedTotalResultsCount;

      DataTable dtResults = new DataTable();
      dtResults.Columns.Add(new DataColumn("Title", typeof(string)));
      dtResults.Columns.Add(new DataColumn("Summary", typeof(string)));
      dtResults.Columns.Add(new DataColumn("URL", typeof(string)));
      for (int i = 0; i < 10; i++)
      {
          DataRow dr = dtResults.NewRow();
          dr[0] =  r.resultElements[i].title;
          dr[1] =  r.resultElements[i].snippet;
          dr[2] = r.resultElements[i].URL;
          dtResults.Rows.Add(dr);
      }
      dataGridView1.DataSource = dtResults;

This is the running application

Login to add your contents and source code to this article
share this article :
post comment
 

Hi I am new to ASP.NET, how would you access the google search API from an ASP aaplication. Thanks Chris

Posted by Christopher Seewald Nov 26, 2008

Good article. Interesting and different. Keep up the good work.

Posted by Mahesh Chand Aug 20, 2006
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor