Click here to Skip to main content
12,701,133 members (29,872 online)
Click here to Skip to main content
Add your own
alternative version

Stats

144.6K views
816 downloads
57 bookmarked
Posted

Google Web Service Client program

, 27 Apr 2002
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Wooseok Seo
Software Developer (Senior)
Korea (Republic of) Korea (Republic of)
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

You may also be interested in...

Pro

Comments and Discussions

 
GeneralSerial key Pin
Bill_IT5-Apr-09 17:39
memberBill_IT5-Apr-09 17:39 
GeneralRe: Serial key Pin
Umass3-Jun-09 7:18
memberUmass3-Jun-09 7:18 
GeneralRe: Serial key Pin
swdev.bali23-Jun-09 19:38
memberswdev.bali23-Jun-09 19:38 
Generalgoogle api Pin
Machvi31-May-08 11:42
memberMachvi31-May-08 11:42 
Generalthanks very much Pin
babylon12844-Apr-07 7:40
memberbabylon12844-Apr-07 7:40 
QuestionLicense key Pin
BHAVANA RAO28-Mar-07 0:25
memberBHAVANA RAO28-Mar-07 0:25 
AnswerRe: License key Pin
Wooseok Seo28-Mar-07 1:27
memberWooseok Seo28-Mar-07 1:27 
GeneralRe: License key Pin
nip9028-Mar-07 22:48
membernip9028-Mar-07 22:48 
GeneralRe: License key Pin
Umass3-Jun-09 7:17
memberUmass3-Jun-09 7:17 
GeneralRe: License key Pin
nip903-Jun-09 8:09
membernip903-Jun-09 8:09 
QuestionException Pin
sir Beans8-Sep-06 2:26
membersir Beans8-Sep-06 2:26 
QuestionDataBinder.Eval() Pin
TheEagle29-Jun-06 23:14
memberTheEagle29-Jun-06 23:14 
GeneralNeed Help Pin
ovia28-Sep-05 1:56
memberovia28-Sep-05 1:56 
GeneralHelp..... Pin
Wiele Met 'n P23-Sep-03 3:02
memberWiele Met 'n P23-Sep-03 3:02 
Generalthanks Pin
ayman2-Jun-03 15:52
memberayman2-Jun-03 15:52 
GeneralRe: thanks Pin
Mahmoud Nasr Ahmed3-Jun-03 23:55
memberMahmoud Nasr Ahmed3-Jun-03 23:55 
GeneralNiiice Pin
keno5-Sep-02 17:33
memberkeno5-Sep-02 17:33 
GeneralDemo Froze up everytime Pin
Soliant20-Aug-02 10:03
memberSoliant20-Aug-02 10:03 
GeneralGood Job Pin
kromozom16-Aug-02 4:34
memberkromozom16-Aug-02 4:34 
General[Smile] Cool job! Pin
Smile Seo28-Apr-02 20:33
memberSmile Seo28-Apr-02 20:33 
GeneralRe: [Smile] Cool job! Pin
Nish [BusterBoy]28-Apr-02 20:41
memberNish [BusterBoy]28-Apr-02 20:41 
GeneralRe: [Smile] Cool job! Pin
asuleman18-Apr-03 23:12
memberasuleman18-Apr-03 23:12 
GeneralRe: [Smile] Cool job! Pin
Smile Seo29-Jun-03 5:44
memberSmile Seo29-Jun-03 5:44 
GeneralRe: [Smile] Cool job! Pin
guy kolb18-Apr-06 4:29
memberguy kolb18-Apr-06 4:29 

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

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

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