Friday, September 9, 2011

Google APIs Client Library for PHP (Beta)

The Google APIs Client Library for PHP has officially reached Beta.

The Google API PHP client supports the following Google APIs right now, with more on the way.

To grab the latest version of the library, simply run the following commands:

curl "http://google-api-php-client.googlecode.com/files/google-api-php-client-0.4.1.tar.gz" -O 
tar -xvf  google-api-php-client-0.4.1.tar.gz
cd google-api-php-client/examples/

Here is some sample code that demonstrates how to use the library and the Google Books API to search for and print the titles of free ebooks by Henry David Thoreau:

<?php
require_once 'path/to/src/apiClient.php';
require_once 'path/to/src/contrib/apiBooksService.php';

$client = new apiClient();
$client->setApplicationName("My_Books_API_Example");
$service = new apiBooksService($client);

$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);

foreach ($results['items'] as $item) {
  print($item['volumeInfo']['title'] . '<br>');
}

Blog: The official Google Code blog
Post: Google APIs Client Library for PHP (Beta)
Link: http://googlecode.blogspot.com/2011/09/google-apis-client-library-for-php-beta.html

No comments:

Post a Comment