setApplicationName("Client_Library_Examples"); $apiKey = ""; // Change to your API key. // Warn if the API key isn't changed! if (strpos($apiKey, "<") !== false) { echo missingApiKeyWarning(); exit; } else { $client->setDeveloperKey($apiKey); $service = new Google_Service_Books($client); /************************************************ To actually make the batch call we need to enable batching on the client - this will apply globally until we set it to false. This causes call to the service methods to return the query rather than immediately executing. ************************************************/ $client->setUseBatch(true); /************************************************ We then create a batch, and add each query we want to execute with keys of our choice - these keys will be reflected in the returned array. ************************************************/ $batch = new Google_Http_Batch($client); $optParams = array('filter' => 'free-ebooks'); $req1 = $service->volumes->listVolumes('Henry David Thoreau', $optParams); $batch->add($req1, "thoreau"); $req2 = $service->volumes->listVolumes('George Bernard Shaw', $optParams); $batch->add($req2, "shaw"); /************************************************ Executing the batch will send all requests off at once. ************************************************/ $results = $batch->execute(); echo "

Results Of Call 1:

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

Results Of Call 2:

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