1. Home
  2. Computing & Technology
  3. Visual Basic

The Google Web Service API
Adding the power of the Google search engine to your VB program

By , About.com Guide

Google

One of the great things about watching the web is seeing new bubbles of success pop out of nowhere and go on to greatness. It happened to the PC itself when 'mainframers' said it was nothing but a toy. It happened to Microsoft when they were David to IBM's Goliath. And it looks like it's happening again in search engines ... which are now one of the key enabling technologies of the Web.

One search engine is rising above the churning froth of technology: Google. What you might not know is that you can use the Google technology right in your own Visual Basic code using the Google Web Service API.

There are actually a lot of ways to use Google (make sure you consult their legal 'terms and conditions' pages before using any of them, however). One of the easiest is to simply cut and paste their canned HTML code from their home page into your web page. It looks like this in HTML:

<center>
<FORM method=GET action="http://www.google.com/search">
<TABLE bgcolor="#FFFFFF"><tr><td>
<A HREF="http://www.google.com/">
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif"
border="0" ALT="Google" align="absmiddle"></A>
<INPUT TYPE=text name=q size=25 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search">
</td></tr></TABLE>
</FORM>
</center>

You can try this out by pasting the HTML above into any web page, even one that is just a file on your local computer.

Variations that search individual sites or filter out adult content are also available. The Google page has more information.

This really avoids the main point, however. What you probably want to do is use Google like an object; get 'down and technical' with methods and properties. That way, you can code your own Google searches that include just exactly the sorts of things that you need in your code. What you need is a Web Service. Google has your answer!

You can download the Google Web APIs developer's kit, which includes both documentation and example code.

In this short article, we'll look briefly at the Google web service API and how it works in Visual Basic. In future articles, I'll cover more advanced topics such as how XML Web Services actually works, how to create your own Schema files using XSD, using the Web Services Description Language (WSDL) and the various options you have with Visual Basic. For now, however, I'm using the "instant gratification" approach. We're just going to 'do it' and get the thrill of seeing it work without getting too deeply into why it works. But check back later for more!

If you're using VB .NET, it couldn't be more simple to try out the Google API. As noted on the Google page, you just download the kit, get a key, and compile the code. Google requires a key to use their service to keep their service from being abused. Each key is limited to 1,000 automated queries per day. But registration for a key is free.

The downloaded kit features a VB .NET example that you can literally unzip and then run. I changed the default properties to About Visual Basic, but other than that, absolutely nothing was changed to get this result. (Wellll ... I did X out my key for the illustration.)

Click Here to see an example of the results. Click the "Back" button in your browser to return.

VB .NET does literally all of the hard part for you. Check out the Solution Explorer to see the only differences that need to be added to an ordinary Windows Application.

If you're using VB 6, then you need to download the Soap Toolkit from Microsoft and do some of these things in your own code. Unfortunately, the Google API toolkit doesn't have an example for VB 6.

This is, of course, only the client side of the process. The larger part of the web services excitement is building the service itself. With either a supporting hosting provider or the IIS Web Server on your own computer, you can program the other side of the process and provide a web service. With VB .NET, it's a matter of using the correct template and removing the comments from three lines of code that are automatically generated.

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Learn Internet VB.NET
  6. The Google Web Service API

©2009 About.com, a part of The New York Times Company.

All rights reserved.