ChatGPT + Google Book API = Bliss!

In 2019, I started walking a few miles each morning. While walking, I would listen to audiobooks. Before I knew it, I was ripping through books at a pretty good pace. So of course, I wanted a way to track the books I was reading and what was on my To Read list. I had already been using GoodReads and was enjoying the social aspects of it, but their UX isn’t great and I wanted more ways to slice and dice my data.

My next step was to build a WordPress-based tool. Then, I added a new database in Notion. All of a sudden, I had 3 different places where I was tracking books, which means I’m doing double and triple data entry. Even if it’s just copy/paste, it’s still annoying and time-consuming.

One final complaint before we get into how I solved my situation. while I enjoy GoodReads & Notion, both are 3rd party tools that could go away at any minute. So, for me, the WordPress-based solution is the one I want to run with. But I don’t want to do is copy/paste the book data and download a cover image for each book. What I really want is an API.

Hello Google Books API!

Over the weekend I was doing some internet searching and ran across the Google Books API. It has apparently been around a while, but it was new to me. After looking at it for a few minutes, it seemed like a much better option than trying to use the GoodReads API (which is no longer open to new users) or the GoodReads RSS feed, which was another avenue I had pursued in the past.

What got me most excited about the API was how much information was available in the JSON dataset for each book. As an example, here’s what’s available for Fight Club. With access to the title, description, author, genres, and book cover, and all of it delivered in an easy-to-digest JSON response, this finally looked like a data source I could work with. Now, I just needed to build an interface.

Oh, and hello ChatGPT!

ChatGPT is one of the biggest things to hit the internet in quite a while. If you haven’t heard of it, ChatGPT is an artificial intelligence chat bot. And, rather than having me butcher an explanation of what it is and what it can do, here’s a pretty cool article about it.

Until now, I’ve been using ChatGPT a bit to help with some writing and mainly just playing around with it. Then, I saw a video where a guy used it to build an entire website. So, I decided to give it a try myself. 90 minutes later, I had a working prototype.

Let Chat GPT do the work

I started out telling ChatGPT what I wanted to do at a very high level.

Seems simple enough, right? Chat GPT thought so.

What I love most about ChatGPT is that you can treat it like you are having a conversation with somebody. If you ask it a question, it remembers the context as you ask additional questions.

I cut off the 10 bullet points that it suggested I do to make my project a reality. Install WordPress, create a plugin, install some plugins, customize some code, etc. But, I’m not here just for a list of things to do. Nope. I’m here for some help making this project come to life.

Within a few seconds, ChatGPT starts typing…

I copied the code and pasted it into my plugin. When I went to the WordPress dashboard, I had a new minute item called “Book Search”. That page looked like this:

Yes. On the very first attempt, I had a working page with a working search box that returned a set of results. Jaw. Drop.

Well, now that I have a list of available books, now I want to import them. Of course, ChatGPT had an answer for that, too.

Adding the import button themselves was a piece of cake. I took this opportunity to update the table layout with some basic CSS, and this was the result.

But, ChatGPT wasn’t done there. It also had suggestions for how to deal with what happens when clicking one of the import buttons.

And, because I’m apparently terrible at screenshots, here’s the rest of what it had to say.

It’s at this point that I did have to do some code tweaking. Mostly because I had named my metadata fields differently than it had suggestions. And at this point, we’ve got a working prototype!

While I’m absolutely loving the process to this point, it wasn’t all sunshine and rainbows. I tried having it help me grab the cover image and save it as the featured image. But, for some reasons that are more technical than I feel like explaining, I cheated and used some code from a buddy to grab and save the image. With that, I was nearly done, but still had some enhancements I wanted to make. I wanted to move the Author and Genre elements into their own custom taxonomies. No surprise, ChatGPT knew what to do.

I was able to cut and paste these pieces into the right spots, and I was off and running!

How I could have used ChatGPT better

Here’s the deal. I’m a programmer. When I looked at the code ChatGPT spit out, it was easy for me to figure out what to do with it. Because of that, I would ask ChatGPT for what I wanted and then I would copy and paste the first response it gave me. Even if that meant I had to modify some of the code myself. But, I didn’t always have to.

With ChatGPT, if you ask it a question and it doesn’t get you the results you’re looking for, it’s simple to ask an add-on question. As you can see above, it kept in mind what I was working on, so asking follow-up questions would have been as easy as saying “that was close, but instead, I’d like the import feature to [insert your clarification]”

No, I haven’t made this available to the public (yet?)

Going from a blank page to a working tool in 90 minutes was super cool. I now have a tool that’s perfectly suitable for personal use. But there are way too many rough edges to even consider making this publicly available.

As I said earlier, there were a few times when I had to touch things up or even write some of my own code to get things working the way I wanted. That’s not to say that ChatGPT couldn’t have helped further. I’m sure I could have asked more questions, asked for more code, asked more clarifying questions, etc, etc.

This does make me curious about how far I could have taken it. Could I ask enough questions to actually turn this into a tool worthy of release? I may have to find out.

Oh, and if you want to see how I’m using it, you can check out my 2019 book list here. (more data entry to come)

Header photo by Luca Bravo on Unsplash

4 Comments

  1. Hello friend,

    I am also building a new website similar to Goodreads and a lot of things you mention in your post actually applies to me and I did many of the things you did as well! However, my project is for the public and is supposed to fetch the books from Google Books API and import it in the layout that was created in my CPT in ACF. For example, book_title, genre, author, ISBN, rating, publish_date are the ACF fields and these need to be imported from the Google Books API. I am kind of stuck on how to move on from here. Another challenge that i’m facing is; how will my WordPress hosting handle millions of records of books. Could you please tell me how you managed to get the featured image as well? This is also something I need for my website, I would really appreciate it.

    Kind regards,

    Volkan

    1. Hey Volkan,
      Thanks for reading. I’m glad you’re finding it useful.
      When you make a call to the Google Books API, it has a whole bunch of information in the response. Including things like title, genre, author, ISBN, and even a URL for a thumbnail image. The code that does the importing and storage of the data was about 80% code I got from ChatGPT and the rest was me taking what they gave me and then improving upon it. Or, at least making it work for what I was trying to do.
      The plugin I’m using to pull the data from Google Books is my own custom plugin that I talk about above. I used ACF to create the fields needed, but everything else is custom and, at this point, not something I plan on releasing as it was just something I was doing to scratch my own itch.
      As for your question about hosting, if you’re planning on building your own GoodReads site with millions of books (and users), you’re likely going to need something more than a shared hosting plan.
      Best of luck to you!

  2. Also, what plugin did you use to link Google Books API key in WordPress, if any? In my case, I want to get the latest published books through a daily sync- do you have any idea how this could be implemented?

    Thank you.

    Volkan

    1. ChatGPT provided the example for connecting to google with the API. There’s a screenshot above that shows how.

Leave a Reply

Your email address will not be published. Required fields are marked *