Ruby on Rails 3 和 Google 图书搜索

发布于 2024-09-18 12:00:07 字数 127 浏览 4 评论 0原文

我正在尝试在 Ruby on Rails 3 应用程序中开始使用 Google Data API 进行 Google 图书搜索,但我什至不知道如何开始。我需要什么宝石?我需要做什么才能做一些简单的事情,比如搜索标题为 Foobar 的书籍?

I'm trying to get started using the Google Data API for Google Book Search in my Ruby on Rails 3 application, and I don't even understand how to get started. What gems do I need? What do I need to do in order to do something simple like searching for books with a title of Foobar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨离汐 2024-09-25 12:00:07

跟进弃用问题:我刚刚发布了 GoogleBooks,这是一个 Ruby 包装器,使用户能够查询书籍完全按照描述的方式。

它已更新以连接到当前的 Google API,因此它不会受到最近弃用的 Google Book Search API 的影响。

Following up on the deprecation issue: I've just published GoogleBooks, a Ruby wrapper that enables users to query for books precisely in the manner described.

It's updated to hook into the present-day Google API, so it's not affected by the recent deprecation of the Google Book Search API.

壹場煙雨 2024-09-25 12:00:07

如果您想使用 Google 图书检索有关图书的信息,可以使用其数据 API: http://code.google.com/apis/books/docs/gdata/developers_guide_protocol.html

http://books.google.com/books/feeds/volumes?q=isbn:9780974514055 将返回包含图书信息的 XML。您可以使用 Nokogiri gem 来解析结果 ( http://nokogiri.org/ )。

需要注意的一件事是,要获取书籍的完整描述,您需要获取条目而不仅仅是提要结果。

以下是如何从 Google 获取图书信息的简短示例:

require 'open-uri'
require 'nokogiri'

class Book
  attr_accessor :title, :description
  def self.from_google(title)
    book  = self.new
    entry = Nokogiri::XML(open "http://books.google.com/books/feeds/volumes?q=#{title}").css("entry id").first
    xml   = Nokogiri::XML(open entry.text) if entry
    return book unless xml

    book.title       = xml.css("entry dc|title").first.text       unless xml.css("entry dc|title").empty?
    book.description = xml.css("entry dc|description").first.text unless xml.css("entry dc|description").empty?
    book
  end
end

b = Book.from_google("Ruby")
p b

If you're looking to use Google Books to retrieve information about books, you can use their data API: http://code.google.com/apis/books/docs/gdata/developers_guide_protocol.html

Making requests to a URL like http://books.google.com/books/feeds/volumes?q=isbn:9780974514055 will return XML with the book's information. You could use the Nokogiri gem to parse the result ( http://nokogiri.org/ ).

One thing to be aware of is that, to get the full descriptions for books, you need to get the entry instead of just the feed results.

Here's a short example of how you could get a book's information from Google:

require 'open-uri'
require 'nokogiri'

class Book
  attr_accessor :title, :description
  def self.from_google(title)
    book  = self.new
    entry = Nokogiri::XML(open "http://books.google.com/books/feeds/volumes?q=#{title}").css("entry id").first
    xml   = Nokogiri::XML(open entry.text) if entry
    return book unless xml

    book.title       = xml.css("entry dc|title").first.text       unless xml.css("entry dc|title").empty?
    book.description = xml.css("entry dc|description").first.text unless xml.css("entry dc|description").empty?
    book
  end
end

b = Book.from_google("Ruby")
p b
那一片橙海, 2024-09-25 12:00:07

如果你想使用API​​,我想你必须使用jruby和他们的java api。不存在用于图书搜索的 ruby​​ api,根据以下内容: http:// /code.google.com/apis/books/docs/gdata/code.html

要与 Google 连接,请尝试使用 gdata gem。
http://code.google.com/apis/gdata/articles/ gdata_on_rails.html#SetupRails

if you want to use the api, i think you will have to use jruby and their java api. no ruby api exists for the book search, according to this: http://code.google.com/apis/books/docs/gdata/code.html

for connecting with google, try using the gdata gem.
http://code.google.com/apis/gdata/articles/gdata_on_rails.html#SetupRails

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文