Understanding the Google API Query
The core of a Google application is the query. Without the query, thereâs no Google data, and without that, you donât have much of an application. Because of its importance, itâs worth taking a little time to look into the anatomy of a typical query.
Query Essentials
The command in a typical Perl-based Google API application that sends a query to Google looks like:
my $results = $google_search -> doGoogleSearch(key
,query
,start
,maxResults
,filter
,restrict
,safeSearch
,lr
,ie
,oe
);
Usually the items within the parentheses are variables, numbers, or
Boolean values (true
or false
).
In the example above, Iâve included the names of the
arguments themselves rather than sample values so you can see their
definitions here:
-
key
This is where you put your Google API developerâs key [Chapter 1]. Without a key, the query wonât get very far.
-
query
This is your query, composed of keywords, phrases, and special syntaxes.
-
start
Also known as the offset, this integer value specifies at what result to start counting when determining which 10 results to return. If this number were 16, the Google API would return results 16-25. If 300, results 300-309 (assuming, of course, that your query found that many results). This is whatâs known as a âzero-based indexâ; counting starts at 0, not 1. The first result is result 0, and the 999th, 998. Itâs a little odd, admittedly, but you get used to it quicklyâespecially if you go on to do much programming. ...
Get Google Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.