YGISAPI - Yamabay's Google Image Search API for VB/ASP Developers
I. What does YGISAPI do, and why supports VB/ASP?
Yamabay's Google Image Search API, or YGISAPI,
is a COM/ActiveX which allows VB/ASP developers to incoporate Google's Image Search
capability into their programs. Google does provide Search API, but no Image Search
API available. There are quite a few Google Image Search API available on the
Internet, but none supports Classic VB/ASP developers as COM/ActiveX.Yamabay's. YGISAPI runs on Windows 2000,
XP, Windows 2003 with Microsoft.NET Framework 1.1 installed.
This zip file contains not just the DLL. It has a sample working VB project and
a sample working asp file showinfo.asp for your reference.
After download and unzip, you will find
a dll called Google.API.ImageSearch_COM.dll
. This is a .NET assembly, in order to make
it COM/ActiveX, we will need to do the following two things:
Step one: register it to Global Assembly Cache. The command
line is
gacutil /i
Google.API.ImageSearch_COM.dll
Step two: make it available to COM/ActiveX. The command line
is
regasm /tlb
Google.API.ImageSearch_COM.dll
(The gacutil.exe and regasm.exe are
usually located at: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 for
Windows XP and 2003 Server. For general information about converting Net
Assembly to ActiveX/COM please refer to: Convert .NET Assembly to ActiveX/COM. )
After you have successfully run this
command, a file Google.API.ImageSearch_COM.tlb
will be generated in the same folder as the
DLL. You VB program will need to reference to this TLB file in order to
use YGISAPI.
III The API of Yamabay's Google Image Search API
Before you can use YGISAPI, you need to Server.CreateObject in ASP, or New, in VB:
ASP: set SearchService =
Server.CreateObject("Google.API.ImageSearch_COM.SearchService")
VB: Dim SearchService As New
Google_API_ImageSearch_COM.SearchService
Then, there is only one API:
Set resp =
SearchService.SearchImages(SearchQuery, StartPosition, ImagesRequired,
NeedSimilarResults)
Where
SearchQuery is the Google Search String,
like "ZiYi Zhang", "Catherine Zeta Jones". To make it more
compatible, it is a good idea to replace space by "+". So "Ziyi+Zhang" or "Catherine+Zeta+Zones".
StartPosition
is an integer index, zero
based, specifying the index of the first image you want to get. 0 is recommended.
ImagesRequired is an integer, specifing how
many images you want to get from this query. Although no hard
limitation, a number betwen 1 and 100 is recommended, considering we are
using string
to pass information back in YGIAPI.
NeedSimilarResults
is of boolean type, specifying whether you'd like to get similar results.
resp is of type
Google_API_ImageSearch_COM.SearchResponse.
Sample:
VB:
Dim resp As
Google_API_ImageSearch_COM.SearchResponse
Set resp =
SearchService.SearchImages("Ziyi Zhang", 0, 5,
False)
ASP:
Dim resp
Set resp =
SearchService.SearchImages("Ziyi Zhang", 0, 5,
False)
Once you get the SearchResponse
resp
, the next
thing is to get the results from the property of resp. There are two properties available
TotalResultsAvailable as
Integer
: number of total available images for you to retrieve.
SearchResultStr as
String
: a "strutured"
string delimited by '!' for different images and '^' for different attributes of that image.
Note that the VB developers can use
Split (resp.SearchImages, '!') to get an array of Image
Structure img, then for each of the Image Structure img, we can do
Split(img, '^') to get the 7 attributes of the Image.
These 7 attributes
are:
Index 0: Image URL
Index 1: Width of Image, in
pixel. You
will need to use CInt() to convert it to Integer.
Index 2: Height of Image,
in pixel. You
will need to use CInt() to convert it to Integer.
Index 3: Size of Image, in
byte. You
will need to use CInt() to convert it to Integer.
Index 4: Thumbnail
URL.
Index 5: Width of Thumbnail, in
pixel. You
will need to use CInt() to convert it to Integer.
Index 6: Height of
Thumbnail, in pixel. You
will need to use CInt() to convert it to Integer.
Sample Code to Enumerate these attributes:
Set resp =
SearchService.SearchImages("Ziyi Zhang", 0, 5, False)
Debug.Print
resp.TotalResultsAvailable t = Split(resp.SearchResultStr, "!")