dev-master
9999999-dev https://github.com/bluora/php-google-books-apiProvides an interface to the Google Books API
MIT
The Requires
The Development Requires
by Rocco Howard
api php google books
Wallogit.com
2017 © Pedro Peláez
Provides an interface to the Google Books API
An easy to use php client for using Google Books API., (*1)
$ composer require bluora/php-google-books-api dev-master
You can also add this package to your composer.json file:, (*2)
"bluora/php-google-books-api": "dev-master", (*3)
Then run composer update to download the package to your vendor directory., (*4)
There are several ways to set the Google API Service account key., (*5)
Using your envionrment file, using putenv in a config file, or at time of use of the GoogleBookApi class instantiation., (*6)
.env file, (*7)
GOOGLE_BOOKS_API_KEY="xxx...xxx"
PHP Configuration, (*8)
putenv('GOOGLE_BOOKS_API_KEY=xxx...xxx'));
$lookup = new GoogleBooksApi(['key' => 'xxx...xxx']);
Let's get The Google story using it's ISBN., (*9)
NOTE: The returned value will be null if the query can't find the record., (*10)
$book = (new GoogleBooksApi())
->isbn('9780553804577')->first();
An associative array of values is returned. The contents of the book data is different based on the geolocation of your the host's IP address., (*11)
This package implements Iterator and Countable so it provides both count and the ability to treat it as an array using a foreach., (*12)
NOTE: Before returning a result, count will load the first page of results., (*13)
$books = (new GoogleBooksApi()) ->search('google'); echo 'Total books in result: ' . count($books) . '; Total pages: '.$lookup->totalPages();
Would output:, (*14)
Total books in result: 511; Total pages: 52
As it implements Interator, calling foreach will load new books as it reaches the end of the current results., (*15)
If you only want to load a certain number of books, then use limit to only load more pages of books., (*16)
NOTE: Setting the limit will automatically set the number of records per page up to an API maximum of 40. After 40, it will request the remaining values in further API calls., (*17)
$books = (new GoogleBooksApi()) ->search('google') ->limit(12); echo 'Total: '.count($lookup)."; Pages: ".$lookup->totalPages()."\n"; foreach ($lookup as $key => $book) { echo $key." - ".$book['title']."\n"; }
Would output:, (*18)
Total: 511; Pages: 43 0 - The Google Legacy 1 - Google 2 - The Google Model 3 - Google Chrome 4 - Using Google AdWords and AdSense 5 - Making Google Adsense Work for the 9 to 5 Professional - Tips and Strategies to Earn More from Google Adsense 6 - Google Search & Rescue For Dummies 7 - Using Google and Google Tools in the Classroom, Grades 5 & Up 8 - Programming Google App Engine 9 - Python for Google App Engine 10 - Google and the Law 11 - Planet Google
You can call all to get the complete array of results., (*19)
$books = (new GoogleBooksApi()) ->search('google') ->limit(12) ->all(); foreach ($books as $key => $book) { echo $key." - ".$book['title']."\n"; }
Provides an interface to the Google Books API
MIT
api php google books