Dec. 20th 2006 - Ralph Weires wrote in with the following (thanks Ralph!):
Dear Geoff,
first of all, thanks for the Google Search API example you placed on your site; it really helped me getting started. Now that I got it working (after some time of experimenting), I have two remarks about your FAQ:
The first is a minor thing: The answer to the last question (regarding the curly brackets) seems a bit odd to me. The curly brackets are AFAIK only needed to indicate that the expression in between is to be interpreted by PHP. Especially if you include array expressions in a string you need to do it this way, or the interpreter will cause an error. Thus, these curly brackets would afterwards not be present in the string $sitequery anyway. So as far as I see it, your possible solution should in the end create the exact same string. I don't know if this might have been different in earlier PHP versions, though (I'm using the latest one).
The more important remark concerns the problem that many people have with the latest PEAR::SOAP version 0.9.1 (deserialization error). I actually found out what the problem is, and also how it is possible to generate the right request using the current PEAR::SOAP version. If you are interested, maybe you can include this hint into the FAQ, too. It's actually very simple, you just have to add one additional line to the code:
Just add the statement
$soapclient->_namespace = 'urn:GoogleSearch';
after creating the SOAP Client, and everything is fine. By this way,
PEAR::SOAP (0.9.1) recognizes that urn:GoogleSearch is really the
current *base* namespace. Then it defines the namespace in the SOAP
Envelope like this:
xmlns="urn:GoogleSearch"
instead of
xmlns:ns4="urn:GoogleSearch"
and also all the function tags like doGoogleSearch, key, q, ... occur
without the ns4 prefix, which caused the Google Web Service to reject
the queries.
Somehow this solution looks kind of strange because we already tell the Client this namespace in the soapoptions, but it works. However, we can omit the namespace entry in the $soapoptions array now, and it will work also.
Q:
I was looking on ways to incorporate the Google API using PHP and I ran into
your example at http://www.googleduel.com/apiexample.php. The example works
perfectly on your page.
I downloaded your source code. I have installed the latest PEAR::SOAP and I
changed the developer key variable. And then I tried running the script on my
web server. First thing I noticed, is that the script simply won't do anything
when Submit is clicked. I noticed the $query variable is never assigned the
value from the textbox "Search Query". So I just put in a dummy value for the
search query, hardcoding it. Now, when I run the script, it gives me this error:
An error #SOAP-ENV:Client occurred!
Error: /search/beta2No Deserializer found to deserialize a
'urn:GoogleSearch:ns4:key' using encoding style
'http://schemas.xmlsoap.org/soap/encoding/'.
A:
Other people have had similar problems. For the first problem (nothing happens and variable is not set), check if the PHP setting "register globals" is set.
For the second problem
(Error: /search/beta2No Deserializer found to deserialize a
'urn:GoogleSearch:ns4:key' using encoding style
'http://schemas.xmlsoap.org/soap/encoding/' .)
please try rolling back to an earlier version of Pear::SOAP. It seems that the newer versions no longer work with the Google API for some reason. I have not figured out why. But the version I was using (which is OK) is 0.7.5.
Q:
Hi,I'm using your php sample code for GOOGLE API ,but i had a problem with
it.
When copy it to my local net ( http://localhost) i can't use it.it doesn't
announce me anything,but when i click the submit button,it doesn't show any
answer and just showing the same page.(because of form action named the same
name)
A:
Check if the PHP setting "register globals" is set. The problem is that PHP no longer has this setting enabled by default for security reasons. You can get around this problem by getting the parameters from the $_REQUEST variable.
For example, add these lines above the main part of code:
$key = $_REQUEST['key'];
$query = $_REQUEST['query'];
Good luck!
Q:
After failing with Pear::SOAP 0.9.1 I've now set it up with the
0.7.5-release as you suggest in the FAQ and that got rid of the error
messages. However, now I don't get anything at all - the call to
doGoogleSearch never returns or never fires correctly.
To do a proper debugging I would like to recreate the right server
environement and wonder therefor what other Pear elements you use at the
server where this thing runs and what versions they are. As far as I can
tell I need HTTP (Request), Net Socket and Net URL. I have the latest
versions but this script might depend on some older versions?
A:
Here is a link to an archive containing the Pear elements that I am using. They are quite old!!
Q:
I wanted to do a site restricted search:
$sitequery = "$query site:{$_SERVER['SERVER_NAME']} $restrict";
But every time I run it I got 0 results. Is my web site is unsearchable?
What do you think?
Thank you for your help a lot.
A:
Try removing the curly brackets. Those don't work when I try the search manually on Google.
Example:
$sitequery = "$query site:" . $_SERVER['SERVER_NAME'] . " $restrict";
You can also try printing out $sitequery and running the search manually to make sure it is correct.
Still stumped? You can send more questions to gpeters@sfu.ca and I will try to help. Good luck!!
-Geoff
Copyright (c) 2005 Geoff Peters