Google通过ISBN搜索API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Google通过ISBN搜索API相关的知识,希望对你有一定的参考价值。
我试图找出如何使用Google Books API按ISBN搜索图书。我需要编写一个搜索ISBN的程序,然后打印出标题,作者和版本。我尝试使用List volumesList = books.volumes.list("");
,但这不允许我按ISBN搜索,我没有找到一种方法来获取我需要的信息(当ISBN放入其中时没有结果)。我现在拥有的是:
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());
}
如果有人有任何关于如何提高效率的建议让我知道。新守则:
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()+"
");
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());
}
答案
你在使用deprecated data API吗?
使用Books API v1(来自Labs),您可以使用查询
https://www.googleapis.com/books/v1/volumes?q=isbn:<your_isbn_here>
例如
https://www.googleapis.com/books/v1/volumes?q=isbn:0735619670
通过其ISBN查询书籍。
您可能需要查看Googles示例代码:BooksSample.java
另一答案
如果我理解你的任务,你不能像开发者指南developer guide中所说的那样尝试。你可以这样做:
BooksService booksService = new BooksService("myCompany-myApp-1");
myService.setUserCredentials("user@domain.com", "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);
现在使用VolumeEntry api查找所需的getXXXX()并在您的代码中使用它。我希望它能帮助您解决问题。
另一答案
$("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>
以上是关于Google通过ISBN搜索API的主要内容,如果未能解决你的问题,请参考以下文章
知识类API调用的代码示例合集:驾考题库ISBN书号查询万年历查询等
Javascript通过豆瓣api实现获取图书的信息(通过图书的isbn号)要如何实现?