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());
}
To find the ISBN search for it on Google Books and check its "About this Book" page. For books published before 1970, use LCCN or OCLC records. You can also link to specific pages in some books.
If you are looking for building a book library app and you want to load a huge data of books then for adding this feature, you have to use a simple API which is provided by Google, and of course, it's free.
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.
The Google Books API can return details of any book from the ISBN code. You get to know the book title, author names, publishing date, publisher and so on. You don't need any keys to use the Google Books API and the details are sent in JSON format that can be fetch using Google Apps Script.
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
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.
$("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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With