Im having trouble using the Google API and PHP i keep getting 502 errors, about every 9 out of 10 times. Do you think it could be a bad version of SOAP, im using PEAR::SOAP v0.9.4. Here's the script
- Code: Select all
<?php
$soap = new SOAP_Client('http://api.google.com/search/beta2');
$params = array(
'key' => 'xlbreL9QFHJQC8CRfdREEIsNbyoIPgeo',
'q' => 'query',
'start' => 0,
'maxResults' => 1,
'filter' => false,
'restrict' => '',
'safeSearch' => false,
'lr' => '',
'ie' => '',
'oe' => ''
);
$results = $soap->call('doGoogleSearch', $params, 'urn:GoogleSearch');
if (PEAR::isError($results)) {
print "Error: " . $results->getCode() . "<br>";
print $results->getMessage();
} else {
$url = $ret->resultElements[0]->URL;
$title = $ret->resultElements[0]->title;
$title = preg_replace('@<[\/\!]*?[^<>]*?>@si', '', $title);
$title = preg_replace('@<[\/\!]*?[^<>]*?@si', '', $title);
print $title . " - " . $url;
}
?>