Google Book Search API to search Related Books with Keywords

Google Book Search API to search Related Books with Keywords:

Searching the books with user keyword is became very easy with google books/google book search API. Book search can be done using author or publisher or book title or isbn etc., using google book search API.

Google Book Search API to search Related Books with Keywords

demo
download

 

 

You need to create Goolgle API Credential to use the google books API:

Go to this link,

https://console.developers.google.com/project/

 

Create a New Project:

creating a project

creating a project

 

Create a New key => Browser Key:

creating a new key to access the API

creating a new key to access the API

 

creating browser key - API key

creating browser key – API key

 

 

Replace the generated key in the below program,

[php]
$google_key ="ENTER_YOUR_GOOGLE_API_KEY";
$google_books_url = "https://www.googleapis.com/books/v1/volumes?q=$searchTerm&orderB=relevance&key=$google_key";
[/php]

 

 

Google Books API Response will be in JSON format:

[plain]
"items": [
{
"kind": "books#volume",
"id": "Eh5NcvegzMkC",
"etag": "GfVAwuN57MA",
"selfLink": "https://www.googleapis.com/books/v1/volumes/Eh5NcvegzMkC",
"volumeInfo": {
"title": "SCJP Sun Certified Programmer for Java 6 Study Guide",
"subtitle": "Exam 310-065",
"authors": [
"Kathy Sierra",
"Bert Bates"
],
"publisher": "McGraw Hill Professional",
"publishedDate": "2008-07-15",
"description": "The Best Fully Integrated Study System Available–Written by the Lead Developers of Exam 310-065 With hundreds of practice questions and hands-on exercises, SCJP Sun Certified Programmer for Java 6 Study Guide covers what you need to know–and shows you how to prepare–for this challenging exam. 100% complete coverage of all official objectives for exam 310-065 Exam Objective Highlights in every chapter point out certification objectives to ensure you’re focused on passing the exam Exam Watch sections in every chapter highlight key exam topics covered Simulated exam questions match the format, tone, topics, and difficulty of the real exam Covers all SCJP exam topics, including: Declarations and Access Control · Object Orientation · Assignments · Operators · Flow Control, Exceptions, and Assertions · Strings, I/O, Formatting, and Parsing · Generics and Collections · Inner Classes · Threads · Development CD-ROM includes: Complete MasterExam practice testing engine, featuring: Two full practice exams; Detailed answers with explanations; Score Report performance assessment tool Electronic book for studying on the go Bonus coverage of the SCJD exam included! Bonus downloadable MasterExam practice test with free online registration.",
"industryIdentifiers": [
{
"type": "ISBN_10",
"identifier": "0071591079"
},
{
"type": "ISBN_13",
"identifier": "9780071591072"
}
],
"readingModes": {
"text": true,
"image": true
},
"pageCount": 851,
"printType": "BOOK",
"categories": [
"Computers"
],
"averageRating": 4.0,
"ratingsCount": 57,
"contentVersion": "2.16.10.0.preview.3",
"imageLinks": {
"smallThumbnail": "http://bks5.books.google.co.in/books?id=Eh5NcvegzMkC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
"thumbnail": "http://bks5.books.google.co.in/books?id=Eh5NcvegzMkC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.co.in/books?id=Eh5NcvegzMkC&printsec=frontcover&dq=scjp&hl=&cd=1&source=gbs_api",
"infoLink": "http://books.google.co.in/books?id=Eh5NcvegzMkC&dq=scjp&hl=&source=gbs_api",
"canonicalVolumeLink": "http://books.google.co.in/books/about/SCJP_Sun_Certified_Programmer_for_Java_6.html?hl=&id=Eh5NcvegzMkC"
},
"saleInfo": {
"country": "IN",
"saleability": "FOR_SALE",
"isEbook": true,
"listPrice": {
"amount": 2976.15,
"currencyCode": "INR"
},
"retailPrice": {
"amount": 2976.15,
"currencyCode": "INR"
},
"buyLink": "http://books.google.co.in/books?id=Eh5NcvegzMkC&dq=scjp&hl=&buy=&source=gbs_api",
"offers": [
{
"finskyOfferType": 1,
"listPrice": {
"amountInMicros": 2.97615E9,
"currencyCode": "INR"
},
"retailPrice": {
"amountInMicros": 2.97615E9,
"currencyCode": "INR"
}
}
]
},
"accessInfo": {
"country": "IN",
"viewability": "PARTIAL",
"embeddable": true,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED_FOR_ACCESSIBILITY",
"epub": {
"isAvailable": true,
"acsTokenLink": "http://books.google.co.in/books/download/SCJP_Sun_Certified_Programmer_for_Java_6-sample-epub.acsm?id=Eh5NcvegzMkC&format=epub&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api"
},
"pdf": {
"isAvailable": true,
"acsTokenLink": "http://books.google.co.in/books/download/SCJP_Sun_Certified_Programmer_for_Java_6-sample-pdf.acsm?id=Eh5NcvegzMkC&format=pdf&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api"
},
"webReaderLink": "http://books.google.co.in/books/reader?id=Eh5NcvegzMkC&hl=&printsec=frontcover&output=reader&source=gbs_api",
"accessViewStatus": "SAMPLE",
"quoteSharingAllowed": false
},
"searchInfo": {
"textSnippet": "The Best Fully Integrated Study System Available–Written by the Lead Developers of Exam 310-065 With hundreds of practice questions and hands-on exercises, SCJP Sun Certified Programmer for Java 6 Study Guide covers what you need to know- …"
}
}
[/plain]

 

 


PHP Program to Extract the Required information from the above JSON:

[php]
<?php
if(isset($_GET["keyword"])){
$searchTerm = $_GET["keyword"];
}else{
$searchTerm = "kalam";
}
$google_key ="ENTER_YOUR_GOOGLE_API_KEY";
$google_books_url = "https://www.googleapis.com/books/v1/volumes?q=$searchTerm&orderB=relevance&key=$google_key";
$str_data= file_get_contents($google_books_url);
$data = json_decode($str_data,true);
$search_term =$searchTerm;
$allBooksLength = count($data["items"]);
for($a=0;$a<$allBooksLength;$a++) {
$authors = "";
$title = "";
$subtitle = "";
$publisher = "";
$published_date = "";
$description = "";
$isbnArr = "";
$isbn_10 = "";
$isbn_13 = "";
$page_count = "";
$categories = "";
$categries = "";
$avgRtng = "";
$ratingsCnt = "";
$imgLinks = "";
$small_image = "";
$image = "";
$lang = "";
$title = $data["items"][$a]["volumeInfo"]["title"];
echo "Book Title >>> ".$title;
echo "\n<br>";
if(isset($data["items"][$a]["volumeInfo"]["subtitle"])){
$subtitle= $data["items"][$a]["volumeInfo"]["subtitle"];
echo "Book Subtitle >>> ".$subtitle;
echo "\n<br>";
}

$publisher = $data["items"][$a]["volumeInfo"]["publisher"];
echo "Book Publisher >>> ".$publisher;
echo "\n<br>";
if(isset($data["items"][$a]["volumeInfo"]["publishedDate"])){
$published_date = $data["items"][$a]["volumeInfo"]["publishedDate"];
echo "Published Date >>> ".$published_date;
echo "\n<br>";
}
if(isset($data["items"][$a]["volumeInfo"]["authors"])){
$authorArr = $data["items"][$a]["volumeInfo"]["authors"];
}
if(isset($data["items"][$a]["volumeInfo"]["industryIdentifiers"])){
$isbnArr= $data["items"][$a]["volumeInfo"]["industryIdentifiers"];
}

if(isset($data["items"][$a]["volumeInfo"]["pageCount"])){
$page_count= $data["items"][$a]["volumeInfo"]["pageCount"];
echo "Page count >>> ".$page_count;
echo "\n<br>";
}

if(isset($data["items"][$a]["volumeInfo"]["categories"])){
$categries= $data["items"][$a]["volumeInfo"]["categories"];
}

if(isset($data["items"][$a]["volumeInfo"]["averageRating"])){
$avgRtng= floatval($data["items"][$a]["volumeInfo"]["averageRating"]);
echo "Ratings Count >>> ".$ratingsCnt;
echo "\n<br>";
}

if(isset($data["items"][$a]["volumeInfo"]["ratingsCount"])){
$ratingsCnt= $data["items"][$a]["volumeInfo"]["ratingsCount"];
echo "Avg Rating >>> ".$avgRtng;
echo "\n<br>";
}

$imgLinks = $data["items"][$a]["volumeInfo"]["imageLinks"];
$small_image = $imgLinks["smallThumbnail"];
echo "Book Small Image URL >>> ".$small_image;
echo "\n<br>";
$image = $imgLinks["thumbnail"];
echo "Book Image URL >>> ".$image;
echo "\n<br>";
$lang =$data["items"][$a]["volumeInfo"]["language"];
echo "Book Language >>> ".$lang;
echo "\n<br>";

$arrlength=count($authorArr);
for($x=0;$x<$arrlength;$x++) {
if(!empty($authors)){
$authors = $authors.",".$authorArr[$x];
}else{
$authors = $authorArr[$x];
}
}

$isbnArrlength=count($isbnArr);
if($isbnArrlength>1){
if($isbnArr[0]["type"] =="ISBN_10"){
$isbn_10 = $isbnArr[0]["identifier"];
echo "ISBN10 >>> ".$isbn_10;
echo "\n<br>";
}
if($isbnArr[1]["type"] =="ISBN_13"){
$isbn_13 = $isbnArr[1]["identifier"];
echo "ISBN13 >>> ".$isbn_13;
echo "\n<br>";
}
}

if(empty($isbn_10) && empty($isbn_13)){
if($isbnArrlength>1){
if($isbnArr[0]["type"] =="ISBN_13"){
$isbn_13 = $isbnArr[0]["identifier"];
}
if($isbnArr[1]["type"] =="ISBN_10"){
$isbn_10 = $isbnArr[1]["identifier"];
}
}
}

if(!empty($categries) && isset($categries)){
$categlength = count($categries);
for($x=0;$x<$categlength;$x++) {
if(!empty($categories)){
$categories = $categories.",".$categries[$x];
}else{
$categories = $categries[$x];
}
}
}
echo "============================================================================================================";
echo "\n<br>";
}
?>
[/php]

 

 

Output:

[plain]
Book Title >>> Sachin
Book Subtitle >>> The Story of the World’s Greatest Batsman
Book Publisher >>> Penguin UK
Published Date >>> 2012-05-24
Page count >>> 448
Ratings Count >>>
Avg Rating >>> 4
Book Small Image URL >>> http://bks9.books.google.com/books?id=PqADCD33q00C&printsec=frontcover&img=1&zoom=5&source=gbs_api
Book Image URL >>> http://bks9.books.google.com/books?id=PqADCD33q00C&printsec=frontcover&img=1&zoom=1&source=gbs_api
Book Language >>> en
[/plain]

Recommended PHP Books:

Leave a Reply