<html>
<head>
<title>Google SOAP Search API example</title>
</head>
<body>
<?php
require_once('nusoap.php');
# Set parameters
$parameters = array(
'key'=> 'obtain your own google api key at http://code.google.com/apis/soapsearch/ and put it there',
'q' => 'NuSphere PHP IDE' ,
'start' => '0',
'maxResults' => '10',
'filter' => 'false',
'restrict' => '',
'safeSearch' => 'false',
'lr' => '',
'ie' => '',
'oe' => ''
);
// creating
$soapclient = new soapclient('http://api.google.com/GoogleSearch.wsdl', 'wsdl');
$err = $soapclient->getError();
if ($err) {
echo '<h2>Failed to access WSDL</h2><pre>' . $err . '</pre>';
} else {
// actual SOAP request
$results = $soapclient->call('doGoogleSearch',$parameters,'urn:GoogleSearch');
$err = $soapclient->getError();
if ($err) {
echo '<h2>SOAP call error</h2><pre>' . $err . '</pre>';
} else {
if ($soapclient->fault) {
echo '<h2>Fault</h2><pre>';
print_r($results);
echo '</pre>';
} else {
echo '<h2>Results:</h2>';
foreach ($results['resultElements'] as $val) {
echo "<a href=" . $val['URL'] . ">" . $val['title'] . "</a><br>";
echo $val['snippet'] . "<br>";
echo $val['URL'] . "<br>";
echo "<br>";
}
}
}
} |
This example shows how to use NuSoap for running queries using Google API.
Before using, please make sure you updated the 'key' element in the $parameters with a valid Google API key you obtained from there
http://code.google.com/apis/soapsearch/