google API

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

google API

Post by malcolmboston »

i have this code in PHP for getting the results page from google through SOAP

Code: Select all

function getGoogleResults () {
      // connect to the soap client
      $soapclient = new soapclient("http://api.google.com/GoogleSearch.wsdl","wsdl");
      // get back a result
      $queryResult = $soapclient->call("doGoogleSearch", $this->searchParameters, "urn:GoogleSearch");
      // and on it go's.............................
now ive had this working before but now whenever i send the request i get this cryptic error message:

Code: Select all

Array
(
    [faultcode] => SOAP-ENV:Server
    [faultstring] => Exception while handling service request: com.google.soap.search.GoogleSearchService.doGoogleSearch([none]) not found.
    [faultactor] => /search/beta2
    [detail] => Array
        (
            [stackTrace] => java.lang.NoSuchMethodException: com.google.soap.search.GoogleSearchService.doGoogleSearch([none]) not found.
   at org.apache.soap.util.MethodUtils.getEntryPoint(MethodUtils.java:134)
   at org.apache.soap.util.MethodUtils.getMethod(MethodUtils.java:548)
   at org.apache.soap.util.MethodUtils.getMethod(MethodUtils.java:528)
   at org.apache.soap.server.RPCRouter.invoke(RPCRouter.java:114)
   at org.apache.soap.providers.RPCJavaProvider.invoke(RPCJavaProvider.java:129)
   at org.apache.soap.server.http.RPCRouterServlet.doPost(RPCRouterServlet.java:288)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at com.google.gse.HttpConnection.runServlet(HttpConnection.java:436)
   at com.google.gse.HttpConnection.run(HttpConnection.java:376)
   at com.google.gse.DispatchQueue$WorkerThread.run(DispatchQueue.java:254)

        )

)
does anyone know what it means and / or how to solve it
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

*bump
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

you're calling a function that doesn't exist.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

no im not, like i said this exact code worked fine about 2 weeks ago, i actually copied and pasted that element of the code from an existing application i built..... although google can change it at anytime as its in Beta they simply would not change that element as it would likely break thousands of existing applications, in fact my first use of the google API i developed a SEO tool for an old job, i hope it has broke :twisted:
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

doGoogleSearch([none])
Why does it say you aren't using any parameters? Could it be that $this->searchParameters is null?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

nope its full, i have a debug mode option in my class that prints out everything... its there and correct
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');
$apiKey = '...';
$searchphrase = 'devnet';
$queryResult = $soapclient->doGoogleSearch($apiKey, $searchphrase, 0, 10, False, '', False, '', 'utf-8', "utf-8");
var_dump($queryResult);
?>

Code: Select all

<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');

$params = array(
		'key'=>'...',
		'q'=>'devnet',
		'start'=>0,
		'maxResults'=>10,
		'filter'=>false,
		'restrict'=>'',
		'safeSearch'=>false,
		'lr'=>'',
		'ie'=>'utf-8',
		'oe'=>'utf-8'
	);

$queryResult = $soapclient->__soapCall('doGoogleSearch', $params);
var_dump($queryResult);
?>
works both fine for me
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

still not working, im baffled, ok some code:

Code: Select all

function getGoogleResults () {
      // connect to the soap client
      $soapclient = new soapclient("http://api.google.com/GoogleSearch.wsdl","wsdl");
      // get back a result
      $queryResult = $soapclient->call('doGoogleSearch', $this->searchParameters);
      if (empty($queryResult)) {
         output::outputWarning('API Failure :: Failed to return a resultset'); // output warning and retry
         $results = $this->getResults ();
      } else {
         return $queryResult;
      }
    }
heres the output

Code: Select all

Array
(
    [key] => ****
    [q] => Carhartt
    [start] => 0
    [maxResults] => 10
    [filter] => 1
    [restrict] => 
    [safeSearch] => 
    [lr] => lang_en
    [ie] => utf-8
    [oe] => utf-8
)

Array
(
    [faultcode] => SOAP-ENV:Server
    [faultstring] => Exception while handling service request: com.google.soap.search.GoogleSearchService.doGoogleSearch([none]) not found.
    [faultactor] => /search/beta2
    [detail] => Array
        (
            [stackTrace] => java.lang.NoSuchMethodException: com.google.soap.search.GoogleSearchService.doGoogleSearch([none]) not found.
	at org.apache.soap.util.MethodUtils.getEntryPoint(MethodUtils.java:134)
	at org.apache.soap.util.MethodUtils.getMethod(MethodUtils.java:548)
	at org.apache.soap.util.MethodUtils.getMethod(MethodUtils.java:528)
	at org.apache.soap.server.RPCRouter.invoke(RPCRouter.java:114)
	at org.apache.soap.providers.RPCJavaProvider.invoke(RPCJavaProvider.java:129)
	at org.apache.soap.server.http.RPCRouterServlet.doPost(RPCRouterServlet.java:288)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at com.google.gse.HttpConnection.runServlet(HttpConnection.java:436)
	at com.google.gse.HttpConnection.run(HttpConnection.java:376)
	at com.google.gse.DispatchQueue$WorkerThread.run(DispatchQueue.java:254)

        )

)

One True Saxon

Array
(
    [key] => ***
    [q] => One True Saxon
    [start] => 0
    [maxResults] => 10
    [filter] => 1
    [restrict] => 
    [safeSearch] => 
    [lr] => lang_en
    [ie] => utf-8
    [oe] => utf-8
)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

did you try

Code: Select all

<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');

$params = array(
                'key'=>'...',
                'q'=>'devnet',
                'start'=>0,
                'maxResults'=>10,
                'filter'=>false,
                'restrict'=>'',
                'safeSearch'=>false,
                'lr'=>'',
                'ie'=>'utf-8',
                'oe'=>'utf-8'
        );

$queryResult = $soapclient->__soapCall('doGoogleSearch', $params);
var_dump($queryResult);
?>
just for testing purposes?

Is your script running with error_reporting E_ALL?
malcolmboston wrote:$soapclient = new soapclient("http://api.google.com/GoogleSearch.wsdl","wsdl");
can't find a second parameter "wsdl" in the manual.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ok i got the error message to stop, but now i get a different error message :( i cant believe tbh im having this many problems with it, ive done this before without a hitch!!

anyway the error message:
Notice: Undefined index: in C:\netserver\www\labs\gQuery\includes\nusoap.php on line 5901
That nusoap file is an absolutely unedited file, total lines is 7241

the code the error is referring to in Nusoap is

Code: Select all

// the next line is line "5899"
$this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name);
            // get final value
            $this->soapresponse = $this->message[$this->root_struct]['result'];
            // get header value: no, because this is documented as XML string
//          if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){
//             $this->responseHeaders = $this->message[$this->root_header]['result'];
//          }
im so baffled my brain is hurting, any ideas anyone?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

also when i run this code which was kindly provided by Volka...

Code: Select all

<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');

$params = array(
                'key'=>'xxx',
                'q'=>'devnet',
                'start'=>0,
                'maxResults'=>10,
                'filter'=>false,
                'restrict'=>'',
                'safeSearch'=>false,
                'lr'=>'',
                'ie'=>'utf-8',
                'oe'=>'utf-8'
        );

$queryResult = $soapclient->call('doGoogleSearch', $params);
var_dump($queryResult);
?>
i get the output:
Notice: Undefined index: in C:\netserver\www\labs\gQuery\includes\nusoap.php on line 5901
string(0) ""
error_reporting (E_ALL) by the way, so does this mean it isnt my code? maybe i have a <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> up nusoap file?? ive just downloaded what is supposedly the latest version and it is still doing it?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you only try this mix of both -your and my- scripts (call != __soapCall)?

please try

Code: Select all

<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');

$params = array(
                'key'=>'...',
                'q'=>'devnet',
                'start'=>0,
                'maxResults'=>10,
                'filter'=>false,
                'restrict'=>'',
                'safeSearch'=>false,
                'lr'=>'',
                'ie'=>'utf-8',
                'oe'=>'utf-8'
        );

$queryResult = $soapclient->__soapCall('doGoogleSearch', $params);
var_dump($queryResult);
?>
as it is, only changing 'key'=>'...'
I tested it with
PHP 5.1.6 (cli) (built: Aug 23 2006 16:35:53)
on winxp and
PHP 5.1.6-pl6-gentoo (cli) (built: Oct 9 2006 19:32:09)
without errors or warnings.


Did you give

Code: Select all

<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');
$apiKey = '...';
$searchphrase = 'devnet';
$queryResult = $soapclient->doGoogleSearch($apiKey, $searchphrase, 0, 10, False, '', False, '', 'utf-8', "utf-8");
var_dump($queryResult);?>
a chance?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

volka wrote:Did you only try this mix of both -your and my- scripts (call != __soapCall)?
PHP tells me thats not a correct method
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Which version of php do you use?
volka wrote:Did you give

Code: Select all

<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');
$apiKey = '...';
$searchphrase = 'devnet';
$queryResult = $soapclient->doGoogleSearch($apiKey, $searchphrase, 0, 10, False, '', False, '', 'utf-8', "utf-8");
var_dump($queryResult);?>
a chance?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

<?php
error_reporting (E_ALL);
require ('includes/gQuery2.class.php');
require ('includes/nusoap.php');
?>
<?php
$soapclient = new SoapClient('http://api.google.com/GoogleSearch.wsdl');
$apiKey = 'xxx';
$searchphrase = 'devnet';
// the next call is not a valid method
//$queryResult = $soapclient->doGoogleSearch($apiKey, $searchphrase, 0, 10, False, '', False, '', 'utf-8', "utf-8");
// so i do this, which ive always done, and worked fine before
$queryResult = $soapclient->call($apiKey, $searchphrase, 0, 10, False, '', False, '', 'utf-8', "utf-8");
var_dump($queryResult);?>
error:

Code: Select all

Notice: Undefined index: in C:\netserver\www\labs\gQuery\includes\nusoap.php on line 5901
string(0) ""
environment:

Code: Select all

PHP: 4.4.0 <!-- i cannot upgrade as my online host is not running PHP5 yet
OS: Windows XP
Post Reply