Getting Started (original) (raw)

This document details the background knowledge that you need in order to use the Google Books API.

  1. Introduction
  2. Before you start
    1. Get a Google account
    2. Get familiar with Books
    3. Learn about authorizing requests and identifying your application
  3. Books API background
    1. Books concepts
    2. Books API data model
    3. Books API operations
  4. Calling style
    1. REST
  5. Data format
    1. JSON

Introduction

This document is intended for developers who want to write applications that can interact with the Google Books API. Google Bookshas a vision to digitize the world's books. You can use the Google Books API to search content, organize an authenticated user's personal library and modify it as well.

Before you start

Get a Google account

You need a Google accountfor testing purposes. If you already have a test account, then you're all set; you can visit the Google Books user interface to set up, edit, or view your test data.

Get familiar with Books

If you're unfamiliar with Google Books concepts, you should read this document and experiment with the user interfacebefore starting to code. This document assumes that you're familiar with web programming concepts and web data formats.

Learn about authorizing requests and identifying your application

When your application requests private data, the request must be authorized by an authenticated user who has access to that data.

In particular, all operations under "My Library" in the Google Books API are considered to be private and require authentication and authorization. In addition, any operation that modifies Google Books data can be performed only by the user who owns that data.

When your application requests public data, the request doesn't need to authorized, but does need to be accompanied by an identifier, such as an API key.

For information about how to authorize requests and use API keys, see Authorizing requests and identifying your application in the Using the API document.

Books API background

Books concepts

Google Books is built upon four basic concepts:

Books API data model

A resource is an individual data entity with a unique identifier. The Books API operates on two types of resources, based on the concepts described above:

The Books API data model is based on groups of resources, called collections:

Volume collection

The volume collection, is a collection of every volume resource managed by Google Books. As such, you cannot list all volume resources, but you can list all volumes that match a set of search terms.

Bookshelf collection

A bookshelf collection consists of all the bookshelf resources managed by Google Books. Bookshelves must always be referenced in the context of a specific user's library. Bookshelves can contain zero or more volumes.

Google provides a set of pre-defined bookshelves for each user:

Example bookshelves:

Books API operations

You can invoke five different methods on collections and resources in the Books API, as described in the following table.

Operation Description REST HTTP mappings
list Lists a specified subset of resources within a collection. GET on a collection URI.
insert Inserts a new resource into a collection (creating a new resource). POST on a collection URI, where you pass in data for a new resource.
get Gets a specific resource. GET on resource URI.
update Updates a specific resource. PUT on resource URI, where you pass in data for the updated resource.
delete Deletes a specific resource. DELETE on resource URI, where you pass in data for the resource to be deleted.

The operations that are supported for the various types of resources are summarized in the table below. Operations that apply to a user's private data are called "My Library" operations, and they all require authentication.

Resource Type Supported Operations
list insert get update delete
Volumes yes* yes
Bookshelves yes* yes, AUTHENTICATED yes* yes, AUTHENTICATED yes, AUTHENTICATED
Reading Positions yes, AUTHENTICATED yes, AUTHENTICATED yes, AUTHENTICATED yes, AUTHENTICATED

*Both AUTHENTICATED and unauthenticated versions of these operations are available, where the authenticated requests operate on the user's private "My Library" data, and unauthenticated requests operate on public data only.

Calling styles

There are several ways to invoke the API:

REST

REST is a style of software architecture that provides a convenient and consistent approach to requesting and modifying data.

The term REST is short for "Representational State Transfer." In the context of Google APIs, it refers to using HTTP verbs to retrieve and modify representations of data stored by Google.

In a RESTful system, resources are stored in a data store; a client sends a request that the server perform a particular action (such as creating, retrieving, updating, or deleting a resource), and the server performs the action and sends a response, often in the form of a representation of the specified resource.

In Google's RESTful APIs, the client specifies an action using an HTTP verb such as POST, GET, PUT, or DELETE. It specifies a resource by a globally-unique URI of the following form:

https://www.googleapis.com/apiName/apiVersion/resourcePath?parameters

Because all API resources have unique HTTP-accessible URIs, REST enables data caching and is optimized to work with the web's distributed infrastructure.

You may find the method definitions in the HTTP 1.1 standards documentation useful; they include specifications for GET, POST, PUT, and DELETE.

REST in the Books API

The supported Books operations map directly to REST HTTP verbs, as described in Books API operations.

The specific format for Books API URIs are:

https://www.googleapis.com/books/v1/{collectionName}/resourceID?parameters

where resourceID is the identifier for a volume or bookshelf resource, and _parameters_ are any parameters to apply to the query. See Query parameter reference for details.

The format of the resourceID path extensions lets you identify the resource you're currently operating on, for example:

https://www.googleapis.com/books/v1/volumes https://www.googleapis.com/books/v1/volumes/volumeId https://www.googleapis.com/books/v1/mylibrary/bookshelves https://www.googleapis.com/books/v1/mylibrary/bookshelves/shelf https://www.googleapis.com/books/v1/mylibrary/bookshelves/shelf/volumes ...

Note that operations with mylibrary in the URI apply only to the currently authenticated user's private library data. The full set of URIs used for each supported operation in the API is summarized in the Books API Reference document.

Here are a couple of examples of how this works in the Books API.

Perform a search for quilting:

GET https://www.googleapis.com/books/v1/volumes?q=quilting

Get information on volume s1gVAAAAYAAJ:

GET https://www.googleapis.com/books/v1/volumes/**s1gVAAAAYAAJ**

REST from JavaScript

You can invoke the Books API using REST from JavaScript (also called JSON-P), using the callback query parameter and a callback function. This allows you to write rich applications that display Books data without writing any server side code.

Note: You can call authenticated methods by passing an OAuth 2.0 token using the access_token parameter. To obtain an OAuth 2.0 token for use with JavaScript, follow the instructions described in OAuth 2.0 for client-side web applications. In the "API Access" tab of the APIs Console, be sure set up a Client ID for web applications, and to use those OAuth 2.0 credentials when getting your token.

The following example uses this approach to display search results for "harry potter":

Books API Example

Data format

JSON

JSON (JavaScript Object Notation) is a common, language-independent data format that provides a simple text representation of arbitrary data structures. For more information, see json.org.