Amit Dangwal
Amit Dangwal

Reputation: 431

how to manuplate the google api php client

how to manuplate this code to get the details of book by passing the isbn number of the book

$client = new \Google_Client();
$client->setApplicationName("BestBook");
$client->setAuthConfigFile('temp.json');
$client->addScope(\Google_Service_Drive::DRIVE);
$client->setDeveloperKey("AIzaSyD6OrKhhJiseBimFVJZ_7OV5tyPdg4LxZiY");

$service = new \Google_Service_Books($client);
$results = $service->volumes->listVolumes('Henry David Thoreau');

foreach ($results as $item) {
  echo $item['volumeInfo']['imageLinks']['smallThumbnail'], "<br /> \n";
}

And any idea why it is showing 10 output when i pass one isbn

Upvotes: 1

Views: 361

Answers (1)

Morfinismo
Morfinismo

Reputation: 5243

Please consider the fact that Google Books provide you ISBN_13 and ISBN_10. Having that in mind you need to do the following:

$client = new Google_Client();
$client->setApplicationName("BestBook");
$client->setDeveloperKey("asdfkjeriuIEWURkjfaskd");

$optParams = array(
    'filter' => 'ebooks'//,
    //'langRestrict' => 'es',
    //'orderBy' => 'relevance'
 );

$isbnNumber = 9781452052656;
$results = $service->volumes->listVolumes($isbnNumber, $optParams);

// HANDLE RESULT
foreach ($results as $item) {     

    if ($item['volumeInfo']['industryIdentifiers'][0]['identifier'] == $isbnNumber ) { // For ISBN_13 (for ISBN_10 use $item['volumeInfo']['industryIdentifiers'][1]['identifier'] )

    echo " - ".utf8_decode($item['volumeInfo']['title']), "<br />";

    } 
}

By the way, since you are not accessing user data but instead just application data then you don't need to use the lines $client->addScope(\Google_Service_Drive::DRIVE); and $client->setAuthConfigFile('temp.json');

Oh! I almost forgot! Please do not post your API Key here because that is sensitive information!

Hope this helps!

Upvotes: 1

Related Questions