Search code examples
pythonapigoogle-books-api

Restrict words in Google Books API


Is there a way to restrict certain words from appearing in a title in google books api. For example, I want to receive data about fantasy books however I keep getting books such as "Guide to Literary Agents 2017" in my search. I was wondering if I could restrict the some words such as "Literary" in my search (or would there be a better way to resolve this problem).

Also this is my api link: https://www.googleapis.com/books/v1/volumes?q=subject: fantasy+ young adult &printType=books&langRestrict= en&maxResults=40&key=APIKey'


Solution

  • Yes, in the Books APIs Developers Guide, I found this.

    To exclude entries that match a given term, use the form q=-term.

    So, in your example you could try something like

    https://www.googleapis.com/books/v1/volumes?q=-Literary&subject:fantasy+young%20adult&printType=books&langRestrict=en&maxResults=40
    

    I didn't see the title Guide to Literary Agents 2017 in the results, so I tried excluding a few other keywords and it does seem to exclude those titles.