How to use the Google Books API in your Application

Rachel Emmer
2 min readApr 29, 2020

Much like creating a calculator or to-do list application, building a book search app is a great opportunity to practice your programming skills and test your ability to integrate various features. The most valuable aspects of building this application include searching, filtering, and sorting data as well as implementing an API, particularly one that’s not your own.

There are countless book APIs available for public use. I decided to use the Google Books API due to its cost (free!) and extensive documentation. According to their documentation, the Google Books API allows your application to perform full-text searches and retrieve book information, viewability, and eBook availability.

If you’re unfamiliar with Google Books, the website encourages you to visit the Getting Started | Google Books APIs page before using the API. Once you are ready to proceed, there are two ways to access the API: an OAuth 2.0 token or an API key. If you are going to be accessing a user’s private data in your application, you must use the OAuth token. In this case, we are simply using the API to search for publicly available books, so no authorization is required.

First, head to the Google Cloud Platform and click on the credentials tab. Here, it might ask you to add a project, where you can simply provide a title for your project and the name of your organization, if you choose. Then it will ask you to select an API. Simply type “books” into the search and select the Books API (you can follow these same steps to integrate any of the Google APIs into your application, just make sure to follow the corresponding documentation). Then you’ll have to add credentials. Fill out the information with the API you’d like to use (Books API), where you’ll be calling this API from (Web Browser — JavaScript), and the type of data you will be accessing (Public Data). Then click “What credentials do I need?” and viola! Google will provide you with your own, unique API key.

To use the API in your project, simply append key=yourAPIKey to your HTTP request URL in your application as a query string parameter. Once you are able to fetch the data that you need, you can add a search bar or any other feature of your choosing to search and filter through the book data and display it how you’d like. This is a great way to practice using HTTP requests, APIs, and an abundance of reliable data to make your application functional and unique.

fetch(`https://www.googleapis.com/books/v1/volumes?q=search-terms&key=your-API-key)
.then(response => response.json())
.then(result => {
this.setState({ books: result.items})
})}

--

--