Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Google.com Web API's

0 views
Skip to first unread message

Anthony Saffer

unread,
Mar 19, 2003, 12:18:43 AM3/19/03
to
Has anyone here used Google's Web API from PHP? If so, do you know of any
tutorials that could help me get started?

Thanks!
Anthony

---
Sick of Spam?
Stop it NOW!!
http://www.safferconsulting.com/spamviper


PoDuck

unread,
Mar 19, 2003, 1:24:03 AM3/19/03
to
how about a google search?

http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=google+web+api+ph
p+tutorial&spell=1

Actually now that I know it exists, I have a new project. :)

"Anthony Saffer" <ant...@nospam.safferconsulting.com> wrote in message
news:3e77fe05$1...@nntp2.nac.net...

Nikolai Chuvakhin

unread,
Mar 20, 2003, 3:31:04 AM3/20/03
to
"Anthony Saffer" <ant...@nospam.safferconsulting.com>
wrote in message news:<3e77fe05$1...@nntp2.nac.net>...
>
> Has anyone here used Google's Web API from PHP?

Sure. :)

> If so, do you know of any tutorials that could help me get started?

You really don't need any... Just get yourself a copy of NewSOAP,
and all you need to do is:

require_once("nusoap.php");
$Query = "Your Google query here";
$start = 0;
$key = "Your Google Key Here";
$parameters = array(
"key" => $key,
"q" => $Query,
"start" => $start,
"maxResults" => 10,
"filter" => false,
"restrict" => "",
"safeSearch" => false,
"lr" => "",
"ie" => "",
"oe" => ""
);
$soapclient = new soapclient("http://api.google.com/search/beta2");
$result = $soapclient->call("doGoogleSearch", $parameters, "urn:GoogleSearch");
$searchtime = $result["searchTime"];
$begin = $start + 1;
$end = $start + $parameters["maxResults"];
echo "<p>Search took <b>$searchtime</b> seconds. ";
echo "<br>Displaying results <b>".$begin."-".$end."</b>: </p>";
$total = $result["estimatedTotalResultsCount"];
if ($total > 0) {
$result = $result["resultElements"];
echo "<dl>";
for ($i = 0; $i < $parameters["maxResults"]; $i++) {
$element = $result[$i];
$url = $element["URL"];
$title = $element["title"];
$snippet = $element["snippet"];
$snippet = str_replace("<br>", " ", $snippet);
echo "<dt>";
echo $begin + $i;
echo ". <a href=\"$url\">$title</a>";
echo "<dd>$snippet <br>";
}
echo "</dl>";
} else {
echo "<p>No results found</p>";
}

If the above seems unclear, e-mail me with any questions you may have.

Cheers,
NC

0 new messages