2017 © Pedro PelĂĄez
 

library google-books

Package for interacting with the Google Books API

image

scriptotek/google-books

Package for interacting with the Google Books API

  • Saturday, February 3, 2018
  • by danmichaelo
  • Repository
  • 6 Watchers
  • 6 Stars
  • 515 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 10 Versions
  • 27 % Grown

The README.md

Build Status Scrutinizer code quality Packagist Gitter, (*1)

php-google-books

Simple PHP package for working with the Google Books API. With Laravel5 integration. Doesn't yet support authentication, so it only works with public data. PRs are welcome., (*2)

Install using Composer

Make sure you have Composer installed, then run, (*3)

composer require scriptotek/google-books

in your project directory to get the latest stable version of the package., (*4)

Usage

Start by creating a new client:, (*5)

require_once('vendor/autoload.php');
use Scriptotek\GoogleBooks\GoogleBooks;

$books = new GoogleBooks(['key' => 'YOUR_API_KEY_HERE']);

Note that you can also use the API without specifying an API key, but you will then get a lower request quota. A UsageLimitExceeded exception is thrown when you reach the quota., (*6)

Working with volumes

Getting a single volume by id:, (*7)

$volume = $books->volumes->get('kdwPAQAAMAAJ');

or by ISBN:, (*8)

$volume = $books->volumes->byIsbn('0521339057');

Search:, (*9)

foreach ($books->volumes->search('Hello world') as $vol) {
    echo $vol->title . "\n";
}

Note that the search() method returns a generator that automatically fetches more results until the result list is depleted. If there are thousands of results this will of course take a long time to fetch, so you probably want to define a limit. Limits can be defined as an option: ['maxResults' => 10] inside the GoogleBooks class., (*10)

Working with bookshelves

Getting a single bookshelf by user id and shelf id:, (*11)

$shelf = $books->bookshelves->get('113555231101190020526', '1002');

List the public bookshelves of a user, and their volumes:, (*12)

foreach ($books->bookshelves->byUser('113555231101190020526') as $shelf) {
    echo "<h2>$shelf->title</h2>\n";
    echo "<ul>\n";
    foreach ($shelf->getVolumes() as $vol) {
        echo "  <li>$vol->title</li>\n";
    }
    echo "</ul>\n";
}

Laravel 5 integration

This project ships with a service provider that you can add to the $providers array in your config/app.php:, (*13)

Scriptotek\GoogleBooks\GoogleBooksServiceProvider::class,

There's also a facade you can add to the $aliases array if you like:, (*14)

'GoogleBooks' => Scriptotek\GoogleBooks\GoogleBooksFacade::class,

Run, (*15)

$ php artisan vendor:publish --provider="Scriptotek\GoogleBooks\GoogleBooksServiceProvider"

to create the config/googlebooks.php configuration file., (*16)

Troubleshooting

If you get 403 Forbidden with, (*17)

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "unknownLocation",
    "message": "Cannot determine user location for geographically restricted operation."
   }
  ],
  "code": 403,
  "message": "Cannot determine user location for geographically restricted operation."
 }
}

it means the Books API failed to locate you based on your ip address. Fix this by specifying the 2 letter ISO639 country code manually using the country option to the constructor:, (*18)

$books = new GoogleBooks(['country' => 'NO']);

The Versions

03/02 2018

dev-master

9999999-dev http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

03/02 2018

v0.2.4

0.2.4.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

09/11 2017

dev-feat-base

dev-feat-base http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

04/11 2017

v0.2.3

0.2.3.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

23/09 2016

v0.2.2

0.2.2.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

22/09 2016

v0.2.1

0.2.1.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

22/09 2016

v0.2.0

0.2.0.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

21/09 2016

v0.1.2

0.1.2.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

21/09 2016

v0.1.1

0.1.1.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø

20/09 2016

v0.1.0

0.1.0.0 http://github.com/scriptotek/google-books

Package for interacting with the Google Books API

  Sources   Download

ISC

The Requires

 

The Development Requires

by Dan Michael O. Heggø