Forum Moderators: coopster
I wrote simple code to comunicate with Google Server useing Google API (http://google.com/apis/):
<?php
$url='http://api.google.com/search/beta2';
$host='api.google.com';
$action='urn:GoogleSearchAction';
$request = '<'.'?xml version="1.0" encoding="ISO-8859-1"?'.'>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:typens="urn:GoogleSearch">
<SOAP-ENV:Body>
<typens:doGoogleSearch xmlns:typens="urn:GoogleSearch">
<key xsi:type="xsd:string">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</key>
<q xsi:type="xsd:string">asdasd</q>
<start xsi:type="xsd:int">0</start>
<maxResults xsi:type="xsd:int">10</maxResults>
<filter xsi:type="xsd:boolean">true</filter>
<safeSearch xsi:type="xsd:boolean">false</safeSearch>
<lr xsi:type="xsd:string"></lr>
<ie xsi:type="xsd:string">latin</ie>
<oe xsi:type="xsd:string">latin</oe>
</typens:doGoogleSearch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
$header[] = "Host: $host";
$header[] = "Accept: text/html;q=0.5, application/soap+xml";
$header[] = "Content-length: ".strlen($request);
$header[] = "Content-Type: text/xml";
$header[] = "Connection: close";
$header[] = "SOAPAction: $action\r\n";
$header[] = $request;
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$data=curl_exec($ch);
curl_close($ch);
print($data);
?>
But there are some errors, this is my output:
HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset=utf-8
Cache-control: private
Transfer-Encoding: chunked
Date: Wed, 03 Aug 2005 10:27:02 GMT
Server: GFE/1.3
Connection: Close<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Exception while handling service request: com.google.soap.search.GoogleSearchService.doGoogleSearch (java.lang.String,java.lang.String,int,int,boolean,boolean,java.lang.String,java.lang.String,java.lang.String) -- no signature match</faultstring>
<faultactor>/search/beta2</faultactor>
<detail>
<stackTrace>java.lang.NoSuchMethodException: com.google.soap.search.GoogleSearchService.doGoogleSearch (java.lang.String,java.lang.String,int,int,boolean,boolean,java.lang.String,java.lang.String,java.lang.String) -- no signature match
at org.apache.soap.util.MethodUtils.getEntryPoint(MethodUtils.java:194)
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:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.google.gse.HttpConnection.runServlet(HttpConnection.java:237)
at com.google.gse.HttpConnection.run(HttpConnection.java:195)
at com.google.gse.DispatchQueue$WorkerThread.run(DispatchQueue.java:201)
</stackTrace>
</detail>
</SOAP-ENV:Fault></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Is anybody here who can help me?
I have PHP Version 4.1.2
Cheers,
tnkywe
[edited by: jatar_k at 4:28 pm (utc) on Aug. 3, 2005]
[edit reason] fixed sidescroll [/edit]
I quickly compared your request with the request generated by my Google API app using PHP5's built in SOAP library, and the only difference I could see was the encoding of the boolean values.
The required encoding is formalised by:
[schemas.xmlsoap.org...]
...which states that boolean is constrained to 0 or 1, not the strings true or false, so try changing the values for filter and safeSearch to 1 and 0 respectively (instead of true and false) and see if that works....