Dear all
I've just been testing the Google API this afternoon. It's fab. I've been using some of the ready-made Perl scripts from the O'Reilly Google Hacks book. I'm now trying to get the PHP example to work. I've got nusoap.php (taken untouched from http://dietrich.ganx4.com/nusoap/index.php) and I've got the following script (googly.php). I've also loaded up the GoogleSearch.wsdl file to my web account - you'll see it specified in my script.
My problem is: it always returns no results. There are no error messages, so I can't work out what's wrong. As far as I can make out from nusoap.php, I do have debugging turned on, so I don't understand why there are no error messages. Here's googly.php - it takes the 'query' variable from a simple form. Everything works, but I always get the 'no results' message. Any hints as to my error? I suspect it may be something stupid, but I can't see it at the minute.
<?php
/*
|googly.php: Process user queries using Google API|
*/
// Doctype declaration, CSS, title and meta-tags
require_once("nusoap.php");
// A load of explanatory HTML stuff
# Set parameters
$parameters = array(
"key"=>"mygooglekey",
"q" => $_GET["query"],
"start" => 0,
"maxResults" => 10,
"filter" => false,
"restrict" => "",
"safeSearch" => false,
"lr" => "",
"ie" => "utf-8",
"oe" => "utf-8"
);
// Create a new SOAP client, feeding it GoogleSearch.wsdl
$soapclient = new soapclient("GoogleSearch.wsdl", "wsdl");
// query Google
$results = $soapclient->call("doGoogleSearch",$parameters);
// Results?
if (is_array($results["resultElements"]))
{
print "<p>Your Google query for \"" . $_GET["query"] . "\" found "
. $results["estimatedTotalResultsCount"] . " results, the top ten of which are:</p>";
foreach ( $results["resultElements"] as $result ) {
print
"<p><a href=\"" . $result["URL"] . "\" target=\"_blank\">" .
( $result["title"] ? $result["title"] : "no title" ) .
"</a><br />" . $result["URL"] . "<br />" .
( $result["snippet"] ? $result["snippet"] : "no snippet" ) .
"</p>";
}
}
// No Results
else {
print "Your Google query for \"" . $_GET["query"] . "\" returned no results";
}
?>
Thanks for any hints you can offer
Norm