images/cc_by_sa_360.png

WARNING: This presentation contains (very little!) code.

DISCLAIMER: I hold (very few!) Google shares.

Google Books v1 API

Google API Console

The Google API Console appears to be Google’s one-stop shop for all of its future APIs:

images/google_api_console.png

A fast happy response

The API is fast, and Google’s customer service can be as well.

A few hours after submitting a request for a quota increase:

images/google_quota_increase.png

A word about authentication

Authentication screenshot

With the Python client, at least, the first time you run a script you are asked to open a URL in a browser to authorize access:

images/google_oauth2_perm_request.png

Search for matching volumes

GET https://www.googleapis.com/books/v1/volumes?q={search terms}

def vol_by_query(self, query):
    "Return the metadata for all results for a given query"

    results = self.service.volumes().list(q=query).execute()

    return results

Response for a successful search

curl 'https://www.googleapis.com/books/v1/volumes?q=apache+derby'
{
   "kind" : "books#volumes",
   "totalItems" : 597,
   "items" : [
      {
         "etag" : "6II3PsLxZfo",
         "accessInfo" : {
            "country" : "CA",
            "publicDomain" : false,
            "accessViewStatus" : "NONE",
            "viewability" : "NO_PAGES",
            "embeddable" : false
         },
         "volumeInfo" : {
            "authors" : [
               "Paul Zikopoulos",
               "George Baklarz",
               "Dan Scott"
            ],
            "imageLinks" : {
               "thumbnail" : "http://bks6.books.google.com/books?id=nrUZAAAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api",
               "smallThumbnail" : "http://bks6.books.google.com/books?id=nrUZAAAACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api"
            },
            "language" : "en",
            "infoLink" : "http://books.google.com/books?id=nrUZAAAACAAJ&dq=apache+derby&ie=ISO-8859-1&source=gbs_api",
            "industryIdentifiers" : [
               {
                  "identifier" : "0131855255",
                  "type" : "ISBN_10"
               },
               {
                  "identifier" : "9780131855250",
                  "type" : "ISBN_13"
               }
            ],
            "publishedDate" : "2005-11-06",
            "previewLink" : "http://books.google.com/books?id=nrUZAAAACAAJ&dq=apache+derby&ie=ISO-8859-1&cd=1&source=gbs_api",
            "description" : "",
            "printType" : "BOOK",
            "subtitle" : "off to the races : includes details of IBM Cloudscape",
            "contentVersion" : "preview-1.0.0",
            "title" : "Apache Derby",
            "pageCount" : 567,
            "publisher" : "IBM Press"
         },
         "selfLink" : "https://www.googleapis.com/books/v1/volumes/nrUZAAAACAAJ",
         "kind" : "books#volume",
         "id" : "nrUZAAAACAAJ",
         "saleInfo" : {
            "country" : "CA",
            "saleability" : "NOT_FOR_SALE",
            "isEbook" : false
         }
      },
      {
         "etag" : "COHHnYS3RpU",
         "accessInfo" : {
            "country" : "CA",
            "publicDomain" : false,
            "accessViewStatus" : "NONE",
            "viewability" : "NO_PAGES",
            "embeddable" : false
         },
         "volumeInfo" : {
            "authors" : [
               "Lambert M Surhone",
               "Mariam T Tennoe",
               "Susan F Henssonow"
            ],
            "language" : "en",
            "infoLink" : "http://books.google.com/books?id=XDlNYgEACAAJ&dq=apache+derby&ie=ISO-8859-1&source=gbs_api",
            "industryIdentifiers" : [
               {
                  "identifier" : "6134618403",
                  "type" : "ISBN_10"
               },
               {
                  "identifier" : "9786134618403",
                  "type" : "ISBN_13"
               }
            ],
            "publishedDate" : "2010-12-14",
            "previewLink" : "http://books.google.com/books?id=XDlNYgEACAAJ&dq=apache+derby&ie=ISO-8859-1&cd=2&source=gbs_api",
            "description" : "",
            "printType" : "BOOK",
            "title" : "Apache Derby",
            "pageCount" : 100,
            "contentVersion" : "preview-1.0.0"
         },
         "selfLink" : "https://www.googleapis.com/books/v1/volumes/XDlNYgEACAAJ",
         "kind" : "books#volume",
         "id" : "XDlNYgEACAAJ",
         "saleInfo" : {
            "country" : "CA",
            "saleability" : "NOT_FOR_SALE",
            "isEbook" : false
         }
      },
      {
         "etag" : "KgL75KhIVJc",
         "accessInfo" : {
            "country" : "CA",
            "publicDomain" : false,
            "accessViewStatus" : "NONE",
            "viewability" : "NO_PAGES",
            "embeddable" : false
         },
         "volumeInfo" : {
            "authors" : [
               "Paul C. Zikopoulos",
               "George Baklarz",
               "Dan Scott"
            ],
            "imageLinks" : {
               "thumbnail" : "http://bks0.books.google.com/books?id=vBQdQwAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api",
               "smallThumbnail" : "http://bks0.books.google.com/books?id=vBQdQwAACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api"
            },
            "language" : "en",
            "infoLink" : "http://books.google.com/books?id=vBQdQwAACAAJ&dq=apache+derby&ie=ISO-8859-1&source=gbs_api",
            "industryIdentifiers" : [
               {
                  "identifier" : "0137080174",
                  "type" : "ISBN_10"
               },
               {
                  "identifier" : "9780137080175",
                  "type" : "ISBN_13"
               }
            ],
            "publishedDate" : "2010-02-04",
            "previewLink" : "http://books.google.com/books?id=vBQdQwAACAAJ&dq=apache+derby&ie=ISO-8859-1&cd=3&source=gbs_api",
            "description" : "",
            "printType" : "BOOK",
            "subtitle" : "Includes Details of IBM Cloudscape",
            "contentVersion" : "preview-1.0.0",
            "title" : "Apache Derby -- Off to the Races",
            "pageCount" : 600,
            "publisher" : "IBM Pr"
         },
         "selfLink" : "https://www.googleapis.com/books/v1/volumes/vBQdQwAACAAJ",
         "kind" : "books#volume",
         "id" : "vBQdQwAACAAJ",
         "saleInfo" : {
            "country" : "CA",
            "saleability" : "NOT_FOR_SALE",
            "isEbook" : false
         }
      }
   ]
}

Add a volume to a bookshelf

  1. Create a bookshelf using the Google Books UI in a browser
  2. Grant access via OAuth2 to your application
  3. POST to https://www.googleapis.com/books/v1/mylibrary/bookshelves/{shelf}/addVolume?volumeId={volumeId} with OAuth2 authentication

Where:

def add_volume(self, shelf_id, vol_id):
    """Add a volume to a user's book shelf"""

    # Requires an empty body argument? Okay.
    res = self.service.mylibrary().bookshelves().addVolume(
        body='', volumeId=vol_id, shelf=shelf_id
    ).execute(self.auth_http)

    return res

Searching a bookshelf

Not currently possible in v1 API.

Wait, what? Help!

No response so far. A bit disappointing. But one can divine a business rationale: force people to land on the Google Books property on the web, collect more usage data, and (possibly) sell books.

OpenLibrary Read API

Goal of the API

images/openlibrary_read_online.png

OpenLibrary Reader