33

I am trying to figure out how to search for a book by ISBN using the Google Books API. I need to write a program that searches for an ISBN then prints out the title, author, and edition. I tried using List volumesList = books.volumes.list(""); but that did not allow me to search by ISBN and I did not see a way to get the information I needed(when an ISBN was placed in it had no results) . What I have right now is:

    JsonFactory jsonFactory = new JacksonFactory();     
    final Books books = new Books(new NetHttpTransport(), jsonFactory);
    List volumesList = books.volumes.list("9780262140874");

    volumesList.setMaxResults((long) 2);

    volumesList.setFilter("ebooks");
    try
    {
        Volumes volumes = volumesList.execute();
        for (Volume volume : volumes.getItems()) 
        {
            VolumeVolumeInfo volumeInfomation = volume.getVolumeInfo();
            System.out.println("Title: " + volumeInfomation.getTitle());
            System.out.println("Id: " + volume.getId());
            System.out.println("Authors: " + volumeInfomation.getAuthors());
            System.out.println("date published: " + volumeInfomation.getPublishedDate());
            System.out.println();
        }

    } catch (Exception ex) {
        // TODO Auto-generated catch block
        System.out.println("didnt wrork "+ex.toString());
    }

If anyone has any suggestions about how to make this more efficient let me know. New Code:

    String titleBook="";

    ////////////////////////////////////////////////
    try
    {                               
        BooksService booksService = new BooksService("UAH");
        String isbn = "9780262140874";
        URL url = new URL("http://www.google.com/books/feeds/volumes/?q=ISBN%3C" + isbn + "%3E");
        VolumeQuery volumeQuery = new VolumeQuery(url);
        VolumeFeed volumeFeed = booksService.query(volumeQuery, VolumeFeed.class);
        VolumeEntry bookInfo=volumeFeed.getEntries().get(0);

        System.out.println("Title: " + bookInfo.getTitles().get(0));
        System.out.println("Id: " + bookInfo.getId());
        System.out.println("Authors: " + bookInfo.getAuthors());
        System.out.println("Version: " + bookInfo.getVersionId());
        System.out.println("Description: "+bookInfo.getDescriptions()+"\n");
        titleBook= bookInfo.getTitles().get(0).toString();
        titleBook=(String) titleBook.subSequence(titleBook.indexOf("="), titleBook.length()-1);
    }catch(Exception ex){System.out.println(ex.getMessage());}
    /////////////////////////////////////////////////
    JsonFactory jsonFactory = new JacksonFactory();     
    final Books books = new Books(new NetHttpTransport(), jsonFactory);
    List volumesList = books.volumes.list(titleBook);   
    try
    {
        Volumes volumes = volumesList.execute();
        Volume bookInfomation= volumes.getItems().get(0);

        VolumeVolumeInfo volumeInfomation = bookInfomation.getVolumeInfo();
        System.out.println("Title: " + volumeInfomation.getTitle());
        System.out.println("Id: " + bookInfomation.getId());
        System.out.println("Authors: " + volumeInfomation.getAuthors());
        System.out.println("date published: " + volumeInfomation.getPublishedDate());
        System.out.println();

    } catch (Exception ex) {
        System.out.println("didnt wrork "+ex.toString());
    }

3 Answers 3

60

Are you using the deprecated data API?

With Books API v1 (from Labs) you could use the query

https://www.googleapis.com/books/v1/volumes?q=isbn:<your_isbn_here>

for example

https://www.googleapis.com/books/v1/volumes?q=isbn:0735619670

to query a book by its ISBN.

You may want to look at Googles example code: BooksSample.java

6
  • The way you suggested is for HTML not java. The way BooksSample does it is the same as I have above and does not allow for search by ISBN.List volumesList = books.volumes.list(query) is the code they used also query is a string. Oct 27, 2011 at 19:41
  • 11
    The query uses a HTTP GET request and receives the response in JSON format, which is language-independent and commonly used in Java. There is no HTML involved.
    – Chris
    Oct 27, 2011 at 21:01
  • 1
    please note: googleapis.com/books/v1/volumes?q=isbn0735619670 return "totalItems": 78 colon fwd! can't belive that's not documented somewhere (atleast i didn't find it) googleapis.com/books/v1/volumes?q=isbn<0735619670> returns "totalItems": 511 but googleapis.com/books/v1/volumes?q=isbn:0735619670 does a exact search and returns "totalItems": 1. Colon FWD! Can't belive that's not documented somewhere (atleast i didn't find it)
    – omni
    Jun 25, 2012 at 18:01
  • @masi Thank you. I changed the query string accordingly.
    – Chris
    Jun 26, 2012 at 13:45
  • 5
    @masi: Thanks! Note that it is also case-sensitive, so q=ISBN:9780321694690 will return the long list, while q=isbn:9780321694690 will return the specific match. Feb 11, 2014 at 21:05
4

Can't you try like this as said in the developers guide developer guide if I did understand your task. You can do like this :

BooksService booksService = new BooksService("myCompany-myApp-1");
myService.setUserCredentials("[email protected]", "secretPassword");

String isbn = "9780552152679";
URL url = new URL("http://www.google.com/books/feeds/volumes/?q=ISBN%3C" + isbn + "%3E");
VolumeQuery volumeQuery = new VolumeQuery(url);
VolumeFeed volumeFeed = booksService.query(volumeQuery, VolumeFeed.class);

// using an ISBN in query gives only one entry in VolumeFeed
List<VolumeEntry> volumeEntries = volumeFeed.getEntries();
VolumeEntry entry = volumeEntries.get(0);

Now using the VolumeEntry api look for your desired getXXXX() and use it in your code.I hope it will help you to solve your problem.

5
  • 1
    Your answer worked pretty well It got me the correct title of the book with the corresponding ISBN. However when even I called bookInfo.getAuthors() it returned a blank list. When printed it looked like the following "Authors: []" Oct 27, 2011 at 20:10
  • 1
    can do bookInfo.getCreators() ? It should return a list of creators as instances of Creator. Then you can get the authors. May be it will work as I did not try it. Have a try.
    – Shahriar
    Oct 27, 2011 at 20:36
  • I was able to get it working with the new code above. Thanks for your help. Oct 27, 2011 at 22:27
  • I just tried the getCreatos and it cut my code in half thank you. Oct 31, 2011 at 19:38
  • I'm not sure I get where the BooksService type is coming from
    – Alioo
    Sep 4, 2013 at 14:49
1

$("form").submit(
  function(e) {
    e.preventDefault();
    var isbn = $('#ISBN').val();
    var isbn_without_hyphens = isbn.replace(/-/g, "");
    var googleAPI = "https://www.googleapis.com/books/v1/volumes?q=" + isbn_without_hyphens;
    $.getJSON(googleAPI, function(response) {
      if (typeof response.items === "undefined") {
        alert("No books match that ISBN.")
      } else {
        $("#title").html(response.items[0].volumeInfo.title);
        $("#author").html(response.items[0].volumeInfo.authors[0]);
        $("#publishedDate").html(response.items[0].volumeInfo.publishedDate);
      }
    });
  }
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
  <strong>Enter ISBN:</strong> <input type="text" id="ISBN" value="9781407170671">
  <input type="submit" id="submit">
</form>
Title: <span id="title"></span>
<br> Author: <span id="author"></span>
<br> Publication date: <span id="publishedDate"></span>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.