I am new to PHP and just tested out using NuSoap to query Google database. The code is written by Harish Kamath. However, it doesn't work without error message. The web server I used support PHP. Also I downloaded the required nusoap.php class file and put it in the same directory with nusearch.php, which query Goodgle database and I have Google's licence key for its APIs. The code is as following:
<html> <head><basefont face="Arial"></head> <body> <?
if (!$_POST['q']) { ?> <h2>Search</h2> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Search term: <input type="text" name="q"> </form> <? } else { // include the class include("nusoap.php");
// create a instance of the SOAP client object $soapclient = new soapclient("http://api.google.com/search/beta2");
// uncomment the next line to see debug messages // $soapclient->debug_flag = 1;
print("Before params"); // testing
// set up an array containing input parameters to be // passed to the remote procedure $params = array( 'key' => 'LHZMFvNQFHJ/jGT0d6N8Iu83QVsz49rr', // 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 );
print("before invoke the doGoogleSearch method");
// invoke the method on the server
$result = $soapclient->call("doGoogleSearch", $params,"urn:GoogleSearch", "urn:GoogleSearch");
print("before printing results");
// print the results of the search
if ($result['faultstring'])
{
?>
<h2>Error</h2>
<? echo $result['faultstring'];?>
<?
}
else
{
?>
<h2>Search Results</h2>
Your search for <b><?=$result['searchQuery']?></b> produced <?=$result['estimatedTotalResultsCount']?> hits.
<br>
<ul>
<?
print("before displaying result");
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> <? } } ?> </body> </html>
Would be very much appreciated if someone can help me out. Thanks,
Daniel
_________________________________________________________________
Get 10Mb extra storage for MSN Hotmail. Subscribe Now! http://join.msn.com/?pgmarket=en-hk
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php