Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use jQuery and Google Books API to load a viewer based on ID instead of ISBN

I am having trouble getting the Google Books API viewer to work with books that are not just "preview" but the completely free "read" versions. The only problem is that I don't see an ISBN for the "read" versions and when I try to use the book "id" with the Google books API viewer it does not work. Let me explain.

Here is a working version of Google books API viewer using a book that has preview only:

This is the book I am using as a reference of a preview only book:

Jessica's Mother by Hesba Stretton

<html>
<head>
<style type="text/css">
#viewer {width:700px;height:80%;padding:30px;margin-left:auto;margin-right:auto;margin-top:20px;background:#fff;box-shadow: 2px 2px 5px 4px #888888;border-radius:10px;}
#viewerCanvas {width:100%;height:100%;}
</style>
<title>Removing the Footer in Google Books Embedded Viewer API Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">

    google.load("books", "0");

    function initialize() {
      var display_options = {showLinkChrome: false};
      var viewer = new   google.books.DefaultViewer(document.getElementById('viewerCanvas'),display_options);

      viewer.load('ISBN:1935626760', bookNotFound, removePreviewFooter);
    }

    function bookNotFound() {
      document.getElementById('viewerCanvas').innerHTML="<h1>No Preview!</h1>";
    }       

    function removePreviewFooter() {
      $('#viewerCanvas > div > div:nth-child(2)').css('display','none');
    }

    google.setOnLoadCallback(initialize);

</script>
</head>

<body style="background:#ececec;">
  <div id="viewer">
    <div id="viewerCanvas"></div>
  </div>
</body>
</html>

This works good for this book since I know the ISBN number, "1935626760"

Here is the question, what about books that are completely free so are not the "preview only" but are "read" version? Can you use jQuery and the Google Books API to have the viewer based off the id instead of the ISBN for those books that do not have an ISBN?

For example, the above code does not work with for following book:

Lost Gip by Hesba Stretton

This book has an id of PmsNAAAAYAAJ but no ISBN number that I can see. Is there a way that I can still use the Google book viewer API even though I only know the id?

Basically, I am trying to get it so I can have an embedded book viewer on my site for books that are "read" version like the book Lost Gip by Hesba Stretton.

If anyone has any ideas or a better way to go about this, I would greatly appreciate it. Thanks!

like image 952
Tim2376 Avatar asked Oct 02 '22 23:10

Tim2376


1 Answers

Yes, there is an answer to this question in the viewer developer guide

Given the ID PmsNAAAAYAAJ use the viewer load method, replacing 'ISBN:1935626760', with 'PmsNAAAAYAAJ' :

viewer.load('PmsNAAAAYAAJ', bookNotFound, removePreviewFooter);
like image 87
OYRM Avatar answered Oct 23 '22 20:10

OYRM