2014-07-11 63 views
0

我正尝试使用Google PHP客户端访问有关图书的信息。 我知道LCCN(国会图书馆控制编号),并希望将其用作我的搜索关键字。 我无法找到有关如何使用php客户端(仅限JSONP)格式化此类键搜索的文档。如何使用PHP客户端通过lccn进行搜索?

<?php 
    require_once 'Google/Client.php'; 
    require_once 'Google/Service/Books.php'; 

    $client = new Google_Client(); 
    $client->setApplicationName('Get_Book_Covers'); 
    $client->setDeveloperKey('key goes here'); 
    $service = new Google_Service_Books($client); 

    $results = $service->volumes->listVolumes('q=lccn:2005580010'); 

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

回答

0

我们必须格式化搜索项为lccn:number。

我们做下面的脚本:

<?php 
require_once 'Google/Client.php'; 
require_once 'Google/Service/Books.php'; 

$client = new Google_Client(); 
$client->setApplicationName('Get_Book_Covers'); 
$client->setDeveloperKey('my_key'); 
$service = new Google_Service_Books($client); 
$searchTerm = "lccn:91067275"; 
$results = $service->volumes->listVolumes($searchTerm); 

foreach ($results as $item) { 
    $thumbnail = $item['volumeInfo']['imageLinks']['smallThumbnail']; 
    echo $item['volumeInfo']['title'], "<br /> \n"; 
    echo "<img src='$thumbnail' alt='hi'/>"; 
} 

?> 
相关问题