Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Google Web Service Client program

0.00/5 (No votes)
27 Apr 2002 1  
A very simple client program that uses Google's web service

Sample Image

This is very simple client program that uses Google's web service. You can download the SDK from Google.

The sample code is like the following.

private void buttonSearch_Click(object sender, System.EventArgs e)
{
    // before search

    //

    labelSearchText.Text = "Searching...";
    labelSearchText.Update();


    // create Google Search object

    //

    GoogleSearchService s = new GoogleSearchService();
    GoogleSearchResult r;


    // call search function

    //

    r = s.doGoogleSearch(
        "",  ; You license key!
        textSearch.Text, 
        0, 
        10, 
        false, "", false, "", "", "");


    // create HTML document to show result

    //

    string strFile = "result.html";
    StreamWriter sw = File.CreateText(strFile);


    // Header inforamtion

    //

    sw.WriteLine("<HTML><HEAD></HEAD><BODY>");


    // Category 

    //

    foreach(DirectoryCategory dc in r.directoryCategories)
    {
        sw.Write("<b>Category</b> : ");
        sw.WriteLine(dc.fullViewableName);
        sw.WriteLine("<br><br><br>");
    }


    // iterate items

    //

    foreach(ResultElement re in r.resultElements)
    {
        // Title

        //

        string strTitle = "<a href=\"" + re.URL + "\">" + 
                          re.title + "</a><br>";
        sw.WriteLine(strTitle);
        
        // snippet

        //

        string strSnippet = re.snippet +"<br>";
        sw.WriteLine(strSnippet);

        // link and cache size

        //

        string strLink = "<a href=\"" + re.URL + "\">" + re.URL + "</a> - " 
                         + re.cachedSize + "<br><br>";
        sw.WriteLine(strLink);

        // 2 line

        //

        sw.WriteLine("<br><br>");
    }


    // file close

    //

    sw.Close();

    
    // result inforamtion

    //

    labelSearchText.Text = textSearch.Text + " 's web search";

    int estResults = r.estimatedTotalResultsCount;
    double ldTime = r.searchTime;
    labelSearchResult.Text = "Total " + Convert.ToString(estResults) + "  " + 
                    "1 - 10 seach result  Total time:" + 
                                         Convert.ToString(ldTime);


    // browsing!

    //

    object obj = null;
    DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
    string strFilePath = di.FullName + "\\" + strFile;
    WebBrowser.Navigate(strFilePath, ref obj, ref obj, ref obj, ref obj);
}


// Google API homepage
//
private void linkLabel1_LinkClicked(object sender, 
                      System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
    object obj = null;

    WebBrowser.Navigate("http://www.google.com/apis/", ref obj, ref obj, 

                        ref obj, ref obj);
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here