PhpRiot
Download Article
Download this article in PDF format with all listings and files.

Price: $5.00 AUD
(Approx. $4.35 USD)

More information
PhpRiot Newsletter
Your Email Address:

More information

Searching Google With The Google API

Building The Procedure Parameters

There are basically three steps to performing a SOAP remote procedure call:

  1. Build the procedure parameters
  2. Call the procedure
  3. Handle/output the result

Okay, so the first thing we do is create the parameters. The parameters for NuSOAP are held in associative array, which means the array key is the parameter name, and the corresponding array value is that parameter’s value.

The minimal set of parameters we need are:

  • key – The Google license key you created
  • q – The term you want to search form

Other parameters you can specify include:

  • start – The first result you want to fetch, starting from 0. For example if you wanted to fetch from the very first result, this value would be 0. If you wanted to fetch the second page of results (at 10 per page), this value would be 10 (because you want results 10-19, so the third page would be 20-29).
  • maxResults – This is the maximum number of results you want to fetch, from 1 to 10.

There are several more you can specify, but this is enough for our purposes. For a full list, see the Google API reference page

So if we were to search for the first page of results for php articles, our parameters look like this:

Listing 1 listing-1.php
<?php
    $parameters = array('key'        => $key,
                        'q'          => 'php articles',
                        'start'      => 0,
                        'maxResults' => 10);
?>

In This Article