gpt4 book ai didi

java - 按 ISBN 搜索的 Google 图书 API 搜索

转载 作者:IT老高 更新时间:2023-10-28 21:18:04 38 4
gpt4 key购买 nike

我想弄清楚如何使用 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()+"\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());
}

最佳答案

您使用的是 deprecated data API ?

Books API v1 (来自实验室)您可以使用查询

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

例如

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

通过 ISBN 查询一本书。

您可能想查看 Google 的示例代码:BooksSample.java

关于java - 按 ISBN 搜索的 Google 图书 API 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7908954/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com