Click here to Skip to main content
Licence 
First Posted 27 Apr 2002
Views 132,250
Downloads 412
Bookmarked 57 times

Google Web Service Client program

By | 27 Apr 2002 | Article
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

About the Author

Wooseok Seo

Software Developer (Senior)

Korea (Republic Of) Korea (Republic Of)

Member

Woo Seok Seo have been a Microsoft MVP for 7 years and have translated several books into Korean. Author of C# Programming for Beginner (DevPress, 2001), he is interested in Debugging techniques and .NET technology. Get in touch with Woo Seok Seo at wooseok.seo@gmail.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSerial key PinmemberBill_IT16:39 5 Apr '09  
GeneralRe: Serial key PinmemberUmass6:18 3 Jun '09  
GeneralRe: Serial key Pinmemberswdev.bali18:38 23 Jun '09  
Generalgoogle api PinmemberMachvi10:42 31 May '08  
Generalthanks very much Pinmemberbabylon12846:40 4 Apr '07  
QuestionLicense key PinmemberBHAVANA RAO23:25 27 Mar '07  
AnswerRe: License key PinmemberWooseok Seo0:27 28 Mar '07  
GeneralRe: License key Pinmembernip9021:48 28 Mar '07  
GeneralRe: License key PinmemberUmass6:17 3 Jun '09  
GeneralRe: License key Pinmembernip907:09 3 Jun '09  
QuestionException Pinmembersir Beans1:26 8 Sep '06  
QuestionDataBinder.Eval() PinmemberTheEagle22:14 29 Jun '06  
GeneralNeed Help Pinmemberovia0:56 28 Sep '05  
GeneralHelp..... PinmemberWiele Met 'n P2:02 23 Sep '03  
Generalthanks Pinmemberayman14:52 2 Jun '03  
GeneralRe: thanks PinmemberMahmoud Nasr Ahmed22:55 3 Jun '03  
GeneralNiiice Pinmemberkeno16:33 5 Sep '02  
GeneralDemo Froze up everytime PinmemberSoliant9:03 20 Aug '02  
GeneralGood Job Pinmemberkromozom3:34 16 Aug '02  
General[Smile] Cool job! PinmemberSmile Seo19:33 28 Apr '02  
When I downloaded API on Google Web APIs and checked its example sources, it reminded me of this example.
 
Even if this example is not great example, it's my pleasure to help you.
 
Good luck~! Blush | :O
GeneralRe: [Smile] Cool job! PinmemberNish [BusterBoy]19:41 28 Apr '02  
GeneralRe: [Smile] Cool job! Pinmemberasuleman22:12 18 Apr '03  
GeneralRe: [Smile] Cool job! PinmemberSmile Seo4:44 29 Jun '03  
GeneralRe: [Smile] Cool job! Pinmemberguy kolb3:29 18 Apr '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 28 Apr 2002
Article Copyright 2002 by Wooseok Seo
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid