LoginSignup
87
85

More than 5 years have passed since last update.

書籍検索に使える登録不要APIちゃんはちょっと足りない

Posted at

書籍で欲しいデータ

  • タイトル
  • 著者名
  • 発刊日(新旧判断)
  • (出版社)
  • (ISBN)

できたらいいこと

書籍を登録するとき、ぜんぶ手入力は大変。
ISBNを入力すれば、あとは検索APIから引っ張ってよしなにしてくれるとコピペ一つで済む。

API要求

  • 登録不要
  • JSONで返ると嬉しい
  • 新旧多くの本に対応してほしい
  • ISBN10 13 あいまいな入力に対応してほしい

  • とりあえずIT技術書圏がカバーできれば :ok:

サイド

JSONで受け取るならクライアントのJavaScriptでしたいかも。
ただ、クロスオリジンリソースシェアリングという仕様の制約がある。

API候補

[Google Books APIs | Google Developers]

サンプル

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


{
 "kind": "books#volumes",
 "totalItems": 1,
 "items": [
  {
   "kind": "books#volume",
   "id": "i1eYjgEACAAJ",
   "etag": "irRLfmjbLkw",
   "selfLink": "https://www.googleapis.com/books/v1/volumes/i1eYjgEACAAJ",
   "volumeInfo": {
    "title": "ITエンジニアのための機械学習理論入門",
    "authors": [
     "中井悦司"
    ],
    "publishedDate": "2015-11-15",
    "description": "機械学習のしくみを学ぶデータサイエンスの本質を理解する。",
    "industryIdentifiers": [
     {
      "type": "ISBN_10",
      "identifier": "4774176982"
     },
     {
      "type": "ISBN_13",
      "identifier": "9784774176987"
     }
    ],
    "readingModes": {
     "text": false,
     "image": false
    },
    "pageCount": 255,
    "printType": "BOOK",
    "maturityRating": "NOT_MATURE",
    "allowAnonLogging": false,
    "contentVersion": "preview-1.0.0",
    "imageLinks": {
     "smallThumbnail": "http://books.google.com/books/content?id=i1eYjgEACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api",
     "thumbnail": "http://books.google.com/books/content?id=i1eYjgEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api"
    },
    "language": "ja",
    "previewLink": "http://books.google.co.jp/books?id=i1eYjgEACAAJ&dq=isbn:4774176982&hl=&cd=1&source=gbs_api",
    "infoLink": "http://books.google.co.jp/books?id=i1eYjgEACAAJ&dq=isbn:4774176982&hl=&source=gbs_api",
    "canonicalVolumeLink": "http://books.google.co.jp/books/about/IT%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E6%A9%9F%E6%A2%B0%E5%AD%A6.html?hl=&id=i1eYjgEACAAJ"
   },
   "saleInfo": {
    "country": "JP",
    "saleability": "NOT_FOR_SALE",
    "isEbook": false
   },
   "accessInfo": {
    "country": "JP",
    "viewability": "NO_PAGES",
    "embeddable": false,
    "publicDomain": false,
    "textToSpeechPermission": "ALLOWED",
    "epub": {
     "isAvailable": false
    },
    "pdf": {
     "isAvailable": false
    },
    "webReaderLink": "http://books.google.co.jp/books/reader?id=i1eYjgEACAAJ&hl=&printsec=frontcover&output=reader&source=gbs_api",
    "accessViewStatus": "NONE",
    "quoteSharingAllowed": false
   },
   "searchInfo": {
    "textSnippet": "機械学習のしくみを学ぶデータサイエンスの本質を理解する。"
   }
  }
 ]
}

:thumbsup: いい点

  • JSON
  • 1書籍内のデータが豊富
  • クロスオリジン考慮必要無し?

:thumbsdown: 悪い点

  • データベースが貧弱。対応書籍が少ない

致命傷。

実践Node.jsプログラミング Node.jsの基礎知識からアプリケーション開発、テスト、配置/応用までスケーラブルで高速なWeb構築に必要なすべて

などなどそれらしい本も検出できない
https://www.googleapis.com/books/v1/volumes?q=isbn:9784798129471

  • 出版社がない

[外部提供インタフェース(API) « 国立国会図書館サーチについて]

サンプル

http://iss.ndl.go.jp/api/sru?operation=searchRetrieve&query=isbn=4774176982


<searchRetrieveResponse><version>1.2</version><numberOfRecords>2</numberOfRecords><nextRecordPosition>0</nextRecordPosition><extraResponseData>
<facets>
  <lst name="REPOSITORY_NO">
    <int name="R100000001">1</int>
    <int name="R100000002">1</int>
    <int name="R100000074">1</int>
  </lst>
  <lst name="NDC">
    <int name="0">2</int>
  </lst>
  <lst name="ISSUED_DATE">
    <int name="2015">2</int>
  </lst>
  <lst name="LIBRARY">
    <int name="京都府立図書館">1</int>
    <int name="佐賀県立図書館">1</int>
    <int name="国立国会図書館">1</int>
    <int name="大阪市立図書館">1</int>
    <int name="大阪府立中央図書館">1</int>
    <int name="広島県立図書館">1</int>
    <int name="愛知県図書館">1</int>
    <int name="沖縄県立図書館">1</int>
    <int name="滋賀県立図書館">1</int>
    <int name="福井県立図書館">1</int>
    <int name="福岡県立図書館">1</int>
    <int name="長崎県立長崎図書館">1</int>
    <int name="香川県立図書館">1</int>
    <int name="高知県立図書館">1</int>
  </lst>
</facets>
  </extraResponseData><records><record><recordSchema>info:srw/schema/1/dc-v1.1</recordSchema><recordPacking>string</recordPacking><recordData>
<srw_dc:dc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xsi:schemaLocation="info:srw/schema/1/dc-v1.1 http://www.loc.gov/standards/sru/dc-schema.xsd">
  <dc:title>ITエンジニアのための機械学習理論入門</dc:title>
  <dc:creator>中井悦司著</dc:creator>
  <dc:description>参考文献: p252-254</dc:description>
  <dc:publisher>技術評論社</dc:publisher>
  <dc:language>jpn</dc:language>
</srw_dc:dc>
      </recordData><recordPosition>1</recordPosition></record><record><recordSchema>info:srw/schema/1/dc-v1.1</recordSchema><recordPacking>string</recordPacking><recordData>
<srw_dc:dc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xsi:schemaLocation="info:srw/schema/1/dc-v1.1 http://www.loc.gov/standards/sru/dc-schema.xsd">
  <dc:title>ITエンジニアのための機械学習理論入門 = Machine Learning for Software Engineers</dc:title>
  <dc:creator>中井悦司 著</dc:creator>
  <dc:subject>機械学習</dc:subject>
  <dc:description>文献あり 索引あり</dc:description>
  <dc:publisher>技術評論社</dc:publisher>
  <dc:language>jpn</dc:language>
</srw_dc:dc>
      </recordData><recordPosition>2</recordPosition></record></records></searchRetrieveResponse>

:thumbsup: いい点

:thumbsdown: 悪い点

  • 発刊日がついていない!出版社よりこっちを!
  • JSONで取得は出来ない。基本XML
  • クロスオリジン対応が必要
    ただし、ついこないだナイスな記事が投稿された
    [YQLを使ってAjaxで外部APIを叩く - Qiita]
    サーバー設定変更できなくて悩んでいたけどクライアントオンリーで取得できるようになる。

たぶん本当はこれがいいのだと思います。

購入経路や情報量などを考えると、やはりAmazonを使えたらそれがいいように思う。

[Lookup by ISBN - Product Advertising API]

<Item>
  <ASIN>076243631X</ASIN>
  <DetailPageURL>
    https://www.amazon.com/Mammoth-Book-Tattoos-Lal-Hardy/dp/076243631X%3FAWSAccessKeyId%3D[Your_AWSAccessKeyId]%26tag%3D[Your_AssociateTag]%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D076243631X
  </DetailPageURL>
  <SalesRank>7483</SalesRank>
  <ItemAttributes>
    <Author>Lal Hardy</Author>
    <Binding>Paperback</Binding>
    <DeweyDecimalNumber>391.65</DeweyDecimalNumber>
    <EAN>9780762436316</EAN>
    <Feature>ISBN13: 9780762436316</Feature>
    <Feature>Condition: New</Feature>
    <ISBN>076243631X</ISBN>
    <Manufacturer>Running Press</Manufacturer>
    <NumberOfItems>1</NumberOfItems>
    <NumberOfPages>512</NumberOfPages>
    <ProductGroup>Book</ProductGroup>
    <PublicationDate>2009-03-10</PublicationDate>
    <Publisher>Running Press</Publisher>
    <Studio>Running Press</Studio>
    <Title>The Mammoth Book of Tattoos</Title>
  </ItemAttributes>
</Item>

どうするか

基本国会図書館。+ Googleから情報があれば追加

二種類両方のデータを使うことで、ISBNのみでのデータ取得を完了させる。
国会図書館に無い本は漏れる。

オートコンプリート程度の補助扱いに

郵便番号を入力すれば住所が自動的に入力されるように、全入力欄を提供するが、最初にISBNを入力させ、APIのデータをフォームに表示。
空欄が残っていたらユーザーに手入力させる。
できないならば諦める。


どっちにしろ思っていたよりちょっと大変。

ISBNという統一番号があれば、発行元とかで本の特定と網羅なんてすでにされているかと思ったが、そうでも無いみたいでちょっと驚いた。

まあISBNは雑誌や訳本で使いまわされるなどというレアケースもあるようですが。
[ISBN 使い回し - Google 検索]

参考文献

  • [YQLを使ってAjaxで外部APIを叩く - Qiita]

  • [GoogleBooksAPIでISBNコードを使って書籍を検索するときのワナ - Qiita]

  • [Hello Absurd World! 書籍情報を取得するためのAPIをいくつか]

  • [書籍検索API - あずまや]

[Google Books APIs | Google Developers]:https://developers.google.com/books/
[外部提供インタフェース(API) « 国立国会図書館サーチについて]:http://iss.ndl.go.jp/information/api/
[YQLを使ってAjaxで外部APIを叩く - Qiita]:http://qiita.com/ragrog/items/cb64de3f9fac9535f70b
[Lookup by ISBN - Product Advertising API]:http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_LookupbyISBN.html
[ISBN 使い回し - Google 検索]:https://www.google.co.jp/search?q=ISBN 使い回し
[GoogleBooksAPIでISBNコードを使って書籍を検索するときのワナ - Qiita]:http://qiita.com/seihmd/items/4cafe204403ac2889145
[Hello Absurd World! 書籍情報を取得するためのAPIをいくつか]:http://elicon.blog57.fc2.com/blog-entry-322.html
[書籍検索API - あずまや]:http://azuma006.hatenablog.com/entry/2015/07/18/231235

付録

google
const request = require('superagent');
  handleSearchBook(formData) {
    request.get('https://www.googleapis.com/books/v1/volumes').query({q:formData.isbn.toString()}).end(function(err, res) {}).type('json')
  }

ndl
const request = require('superagent');
  handleSearchBook(formData) {
    const ndl = 'https://iss.ndl.go.jp/api/sru?operation=searchRetrieve&query=isbn=' + formData.isbn.toString()
    request.get('http://query.yahooapis.com/v1/public/yql').query({q:'select * from xml where url="' + ndl + `"`, format:'xml'}).end(function(err, res) {}).type('jsonp xml')
  }

87
85
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
87
85