Categories

Archives

Syndication


Google REST API code

27
Apr
Posted in PHP, Programming

Google recently released a new REST API which will replace their old SOAP API (which they haven’t given out keys for since 2006)

This is very good news for those who want to do searchqueries “server-side”.

Documentation: http://code.google.com/apis/ajaxsearch/doc…entation/#fonje
Video: http://google-code-updates.blogspot.com/20…om-outside.html

Here’s some PHPcode of how to use this API:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
$url = “http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Hello%20World”
 
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, “http://www.knark.com”);
$body = curl_exec($ch);
curl_close($ch);
 
// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results…
?>
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Technorati
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Furl
  • Netscape
  • De.lirio.us

Leave us a comment