Categories

Archives

Syndication


Archive for April, 2008

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

Google släppte igår ett nytt REST API som skall ersätta deras SOAP API (som de slutade att dela ut API nyckar till 2006):

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…
?>