Page 1 of 1

Getting Google Search Results using API without buffer

Posted: Wed Mar 15, 2006 10:09 pm
by anjanesh
This small code which I got from the net works but I dont want to use buffer.
How do I get the contents directly ?

Code: Select all

<pre>
<?php
ob_start(); # Need to get rid of this
require_once('nusoap/lib/nusoap.php');

$google_key = 'google_api_key';
$wsdl_url = 'http://api.google.com/GoogleSearch.wsdl';
$q = "some search term";
$parameters = array(
                    'key'          => $google_key,
                    'q'            => $q,
                    'start'        => 0,
                    'maxResults'   => 3,
                    'filter'       => FALSE,
                    'restrict'     => '',
                    'safeSearch'   => FALSE,
                    'lr'           => 'lang_en',
                    'ie'           => '',
                    'oe'           => ''
                   );

$soap_client = new soapclient($wsdl_url, 'wsdl');
$results = $soap_client->call('doGoogleSearch', $parameters);

print_r($results);

$contents = ob_get_clean(); # Need to get rid of this
print_r($contents); # Need to get this same $contents without the use of buffer
?>
Any ideas ? Thanks.

Posted: Wed Mar 15, 2006 10:20 pm
by feyd
read the print_r() manual page. ;)

Posted: Wed Mar 15, 2006 10:36 pm
by anjanesh
This code does seem to work without buffer after all.
But most of the times I got to keep hitting the refresh button.
Most of the times $results is just blank ! Every 5th or so refresh hit brings up $results !

Code: Select all

<pre>
<?php
require_once('nusoap/lib/nusoap.php');

$google_key = 'google_api_key';
$wsdl_url = 'http://api.google.com/GoogleSearch.wsdl';
$q = "some search term";
$parameters = array(
                    'key'          => $google_key,
                    'q'            => $q,
                    'start'        => 0,
                    'maxResults'   => 3,
                    'filter'       => FALSE,
                    'restrict'     => '',
                    'safeSearch'   => FALSE,
                    'lr'           => 'lang_en',
                    'ie'           => '',
                    'oe'           => ''
                   );

$soap_client = new soapclient($wsdl_url, 'wsdl');
$results = $soap_client->call('doGoogleSearch', $parameters);

print_r($results);
?>
IS this a google issue or nuSOAP issue ?

Posted: Wed Mar 15, 2006 10:49 pm
by feyd
could be a timeout issue..

Posted: Wed Mar 15, 2006 10:53 pm
by anjanesh
I wish I can get the direct XML file, then I can handle these issues myself.

Also, its mentioned here :
Note: if you are playing with nusoap on PHP 5, it will throw an error as the nusoap class has the same name as the SOAP client in PHP 5: soapclient.
Thats strange because, Im on PHP 5.1.2 and no errors so far !