Forum Moderators: open

Message Too Old, No Replies

Web API troubleshooting

problems with doGoogleSearch()

         

Giuseppe

8:48 am on Aug 11, 2002 (gmt 0)



HI!
Excuse me if this problem is a little annoying.
When I try to invoke doGoogleSearch() the $result array contains
stdClass Object
(
[documentFiltering] =>
[estimatedTotalResultsCount] => 0
[directoryCategories] =>
[searchTime] => 0.00101
[resultElements] =>
[endIndex] => 0
[searchTips] => [searchComments] =>
[startIndex] => 0
[estimateIsExact] =>
[searchQuery] =>
)

Why there's nothing inside it?
Thanks in advance.
Giuseppe.

Here the script.

<?php

include("SOAP/Client.php");
// Google search query
$query = 'soap';
// Your google license key
$key = 'my key';
$s = new SOAP_Client('http://api.google.com/search/beta2');
$result = $s->call('doGoogleSearch', array(
'key' => $key,
'q' => $q,
'start' => 0,
'maxResults' => 10,
'filter' => false,
'restrict' => '',
'safeSearch' => false,
'lr' => '',
'ie' => '',
'oe' => '',
), 'urn:GoogleSearch');
// Is result a PEAR_Error?
if (get_class($result) == 'pear_error') {
$message = $result->message;
$output = "An error occured: $message<p>";
}
else {

print_r($result);
print "<br>\n";
// We have proper search results
$num = $result['estimatedTotalResultsCount'];
$elements = $result['resultElements'];
$list = '';
if ($num > 0) {
foreach ($elements as $item) {
$size = $item['cachedSize'];
$title = $item['title'];
$url = $item['URL'];
$snippet = $item['snippet'];
$desc = "<p><b>$title</b> - <a href=\"$url\">$url</a> <small>[Size: $size]</small></p>";
$desc .= "\n<blockquote>$snippet</blockquote>\n\n";
$list .= $desc;
}
}
$output = "$num results returned:\n\n$list";
}
echo $output;
?>