How to use the Google Books API

Whether you're planning on making a book shop project or just need to dynamically get book cover images or other information, the Google Books API is probably the best resource you'll find on the internet. The following is a tutorial on how to access and apply Google Books API data to your React application.

Getting access to the Google Books API

There is one thing that we must do before pulling data from this API. Because the Google Books API requires a user-specific API key, we must first set up our project on The Google API Dashboard to generate one.

Depending on if you have a google account that is registered as a developer account, you may be asked to follow some extra steps here to get set up. If so, no sweat. This process will be quick.

Once logged in, click the "New Project" button, which will take you to a page asking you to provide a project name and organization (if applicable).

Screen Shot 2022-07-17 at 9.38.17 PM.png

Back on the dashboard page, you should see a left sidebar with several options. You will first want to navigate to the top section, "Enabled APIs and Services". Here you will see a blue plus symbol along the top bar, accompanied by "ENABLE APIs AND SERVICES".

Search "books API" in the search bar. The first result will be what we want. Go ahead and enable this API. Screen Shot 2022-07-17 at 5.03.07 PM.png

With the Google Books API enabled for this project, we can navigate to "Credentials" on the side navbar. Here we will see empty tables for API keys, Auth client I.D.s and Service accounts. To create a new API key, click "CREATE CREDENTIALS" > "API key".

Screen Shot 2022-07-17 at 10.16.52 PM.png

You will see a new API key appear on the page. Click "SHOW KEY" and copy the key when it is shown.

Using your API key

With the API key, accessing the API to grab specific books with a search query will be as simple as using a GET fetch request to googleapis.com/books/v1/volumes?q=[yourSear...

If Google recognizes your search query and API key, your response will be an array of objects containing data for each book.

This works great on its own, but there are some extra parameters that you can include if you want more specific results (all of the following can be added between the volumes?q=[] and &key:

Filtering Several options are available to narrow down based on viewability.

&filter=...

  • partial Returns results where a partial preview of the text is available

  • full Returns results where the full text is available to preview

  • ebooks Returns results where an ebook version is available

  • free-ebooks Returns results where an ebook version is available for free

  • paid-ebooks Returns results where an ebook version is available for a price

Print Type Restrict results based on print type.

&printType=...

  • all Does not restrict print type

  • books Returns only books

  • magazines Returns only magazines

Pagination Controls the number of results returned.

&startIndex=... The position within the results where return starts. The index of the first item is 0.

&maxResults=... The maximum number of results to return. The default is 10, with the maximum possible being 40.

Query Keywords

While the q parameter is required, you can add keywords to it to make the query more specific.

Keywords can be added like so:

https://www.googleapis.com/books/v1/volumes?q=grinch+inauthor:suess

The keyword options are:

  • intitle Returns results where the query terms are found in the title

  • inauthor Returns results where the query terms are found in the author

  • inpublisher Returns results where the query terms are found in the publisher

  • subject Returns results where the query terms are found in the subject

  • isbn Returns results where the query terms are found in the ISBN

  • lccn Returns results where the query terms are found in the Library of Congress Control Number

  • oclc Returns results where the query terms are found in the Online Computer Library Center number

Conclusion

While the options provided are rather barebones, there are still some more specific parameters that I chose to leave out. You can view them on the Google Books API docs.

Despite said limits in parameters, the Google Books API is extremely useful and dense. One suggestion I will note is that there is a daily quota of 1000 calls to the API by default, which can be extended per request on the Google Developer Dashboard. This is worth noting though it is not likely that many will hit this quota in their usage of the API.

Good luck and happy coding!