Google API & php VIA soap
Posted: Thu Apr 15, 2004 10:50 am
Hi all,
I have been wrestling with Google and SOAP for the last few days and well, it has took me 3 days to get PEAR / SOAP working just to find I can't get any results out of google for some bizarre reason.
The code is as follows:
If I were to print_r($result); I get the array of results returned, obviously not in a nice format but it proves I get results.
What am I doing wrong here, I can't see the wood for the trees anymore....especially after trying to get Pear & SOAP up and running
I have been wrestling with Google and SOAP for the last few days and well, it has took me 3 days to get PEAR / SOAP working just to find I can't get any results out of google for some bizarre reason.
The code is as follows:
Code: Select all
<?php
if (!$_POSTї'q'])
{
?>
<h2>Search</h2>
<form action="<?=$_SERVERї'PHP_SELF']?>" method="post">
Search term: <input type="text" name="q">
<input type="submit" name="Submit" value="Submit">
</form>
<?
}
else
{
// include the class
include("SOAP/Client.php");
// create a instance of the SOAP client object
$soapclient = new SOAP_Client('http://api.google.com/search/beta2');
// set up an array containing input parameters to be
// passed to the remote procedure
$params = array(
'key' => 'MyKeyIsPrivate', // Google license key
'q' => $_POSTї'q'], // search term
'start' => 0, // start from result n
'maxResults' => 10, // show a total of n results
'filter' => true, // remove similar results
'restrict' => '', // restrict by topic
'safeSearch' => true, // remove adult links
'lr' => '', // restrict by language
'ie' => '', // input encoding
'oe' => '' // output encoding
);
// invoke the method on the server
$result = $soapclient->call("doGoogleSearch", $params, "urn:GoogleSearch");
// print the results of the search
if (PEAR::isError($result))
{
?>
<h2>Error</h2>
<? echo $resultї'faultstring'];?>
<?
}
else
{
?>
<h2>Search Results</h2>
<? echo $resultї'estimatedTotalResultsCount'] . " hits
found in " . $resultї'searchTime'] . " ms"; ?>
<ul>
<?
if (is_array($resultї'resultElements']))
{
foreach ($resultї'resultElements'] as $r)
{
echo "<li><a href=" . $rї'URL'] . ">" .
$rї'title'] . "</a>";
echo "<br>";
echo $rї'snippet'] . "(" . $rї'cachedSize'] .
")";
echo "<p>";
}
}
?>
</ul>
<?
}
}
?>What am I doing wrong here, I can't see the wood for the trees anymore....especially after trying to get Pear & SOAP up and running