如何通过传递图书的isbn编号来编写此代码以获取书籍的详细信息
$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";
}如果我传递一个isbn,它为什么会显示10个输出?
发布于 2016-11-18 13:59:43
请考虑Google为您提供ISBN_13和ISBN_10这一事实。考虑到这一点,您需要做以下工作:
$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 />";
}
}顺便说一句,由于您不是访问用户数据,而是只访问应用程序数据,所以您不需要使用行$client->addScope(\Google_Service_Drive::DRIVE);和$client->setAuthConfigFile('temp.json');
噢!我差点忘了!请不要在这里张贴您的API密钥,因为这是敏感的信息!
希望这能有所帮助!
https://stackoverflow.com/questions/40676072
复制相似问题