setApplicationName("Client_Library_Examples"); $apiKey = ""; // Change this line. // Warn if the API key isn't changed. if (strpos($apiKey, "<") !== false) { echo missingApiKeyWarning(); exit; } $client->setDeveloperKey($apiKey); $service = new Google_Service_Books($client); /************************************************ We make a call to our service, which will normally map to the structure of the API. In this case $service is Books API, the resource is volumes, and the method is listVolumes. We pass it a required parameters (the query), and an array of named optional parameters. ************************************************/ $optParams = array('filter' => 'free-ebooks'); $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams); /************************************************ This call returns a list of volumes, so we can iterate over them as normal with any array. Some calls will return a single item which we can immediately use. The individual responses are typed as Google_Service_Books_Volume, but can be treated as an array. ***********************************************/ echo "

Results Of Call:

"; foreach ($results as $item) { echo $item['volumeInfo']['title'], "
\n"; } /************************************************ This is an example of deferring a call. ***********************************************/ $client->setDefer(true); $optParams = array('filter' => 'free-ebooks'); $request = $service->volumes->listVolumes('Henry David Thoreau', $optParams); $results = $client->execute($request); echo "

Results Of Deferred Call:

"; foreach ($results as $item) { echo $item['volumeInfo']['title'], "
\n"; } echo pageFooter(__FILE__);