如何制作google api php客户端

如何制作google api php客户端,php,api,google-api,google-api-php-client,Php,Api,Google Api,Google Api Php Client,如何通过传递图书的isbn号来手动输入此代码以获取图书的详细信息 $client = new \Google_Client(); $client->setApplicationName("BestBook"); $client->setAuthConfigFile('temp.json'); $client->addScope(\Google_Service_Drive::DRIVE); $client->setDeveloperKey("AIzaSyD6OrKhhJis

如何通过传递图书的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";
}
$client=new\Google_client();
$client->setApplicationName(“BestBook”);
$client->setAuthConfigFile('temp.json');
$client->addScope(\Google\u Service\u Drive::Drive);
$client->setDeveloperKey(“AIzaSyD6OrKhhJiseBimFVJZ_7OV5tyPdg4LxZiY”);
$service=new\Google\u service\u Books($client);
$results=$service->volumes->listVolumes('Henry David Thoreau');
foreach($结果作为$项){
echo$item['volumeInfo']['imageLinks']['smallThumbnail'],“
\n”; }

当我通过一个ISBN

< P>时,请考虑它为什么显示10的输出。请考虑谷歌图书为您提供ISBN13和ISBNY10的事实。考虑到这一点,您需要执行以下操作:

$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=new Google_client();
$client->setApplicationName(“BestBook”);
$client->setDeveloperKey(“asdfkjeriuIEWURkjfaskd”);
$optParams=阵列(
“过滤器”=>“电子书”/,
//“langRestrict”=>“es”,
//“排序依据”=>“相关性”
);
$isbnNumber=9781452052656;
$results=$service->volumes->listVolumes($isbnNumber,$optParams);
//处理结果
foreach($results作为$item){
如果($item['volumeInfo']['industryIdentifiers'][0]['identifier']=$isbnNumber){//对于ISBN_13(对于ISBN_10,使用$item['volumeInfo']['industryIdentifiers'][1]['identifier'])
echo“-.utf8_解码($item['volumeInfo']['title']),“
”; } }
顺便说一句,由于您不访问用户数据,而只是访问应用程序数据,因此您不需要使用行
$client->addScope(\Google\u Service\u Drive::Drive)
$client->setAuthConfigFile('temp.json')

哦!!我差点忘了!请不要在这里发布API密钥,因为这是敏感信息


希望这有帮助

如果你把“亨利·大卫·梭罗”改成isbn号,会发生什么事?它可以工作,但我不知道为什么它会显示10个结果,比如10个图像**将你的API密钥保密。如果有人获得了你的密钥,他们可能会使用它来消耗你的配额,或者对你的Google API控制台项目收取费用。耶,谢谢兄弟,我现在已经生成了一个新的密钥。你有没有解决过这个问题?同样的问题,谢谢你的回答,但它显示了许多错误,比如未定义的变量$optparams,我已经让jst开始使用api,所以我dnt knw完美的方式,并且我已经通过了temp.json中的配置设置,如果我不使用它,那么我会传递我的api密钥吗?sry它只显示这个错误cURL error 7:(参见)如果你从这个东西开始,我强烈建议按照这里的说明来做。这将有助于您理解这是如何工作的。