Amazon Webサービスは、SOAPとRESTの両方をサポートしています。RESTの方がシンプルなので、ここではREST APIを使って解説します。
Amazon Webサービスはできることが多い分、先に紹介したGoogleやYahoo!のAPIに比べて仕様が少し大きめです。とはいっても、「URLでパラメータを組み立ててHTTPのGETメソッドでアクセス、そのレスポンスをXMLで受け取る」という基本は変わりません。例えばPerl関連の書籍を探すためには、リスト1のURLでクエリを飛ばします*。すると、リスト2のようなPerl関連の書籍の情報がXMLで返ってきます。
http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService&SubscriptionId=**********&Operation=ItemSearch&ResponseGroup=Small,Images&Keywords=Perl&SearchIndex=Books
<?xml version="1.0" encoding="UTF-8"?>
<ItemSearchResponse
xmlns="http://webservices.amazon.com/AWSECommerceService/2005-03-23">
<OperationRequest>
:
:
<Items>
<Request>
<IsValid>True</IsValid>
<ItemSearchRequest>
<Keywords>Perl</Keywords>
:
:
</ItemSearchRequest>
</Request>
<TotalResults>152</TotalResults>
<TotalPages>16</TotalPages>
<Item>
<ASIN>4873111269</ASIN>
<DetailPageURL>http://www.amazon.co.jp/exec/obidos/redirect?tag=ws%26link_code=xm2%26camp=2025%26creative=165953%26path=http://www.amazon.co.jp/gp/redirect.html%253fASIN=4873111269%2526location=/o/ASIN/4873111269%25253FSubscriptionId=********</DetailPageURL>
<SmallImage>
<URL>http://images.amazon.com/images/P/4873111269.09._SCTHUMBZZZ_.jpg</URL>
<Height>60</Height>
<Width>46</Width>
</SmallImage>
<MediumImage>
:
:
</MediumImage>
<LargeImage>
:
:
</LargeImage>
<ItemAttributes>
<Author>ランダル・L. シュワルツ</Author>
<Author>トムフェニックス</Author>
<Creator Role="著">ランダル・L.シュワルツ</Creator>
:
:
<ProductGroup>Book</ProductGroup>
<Title>初めてのPerl</Title>
</ItemAttributes>
</Item>
<Item>
<ASIN>4839912653</ASIN>
:
:
</Item>
</Items>
</ItemSearchResponse>
書籍名や著者名に加えて、商品のISBN(ASIN*)やURL、それから画像のURLなんかが入っていますね。URLパラメータを組み替えることで、在庫状況や価格などいろいろなデータも同時に取得できます。このXML文書をパースすることで、任意のキーワードに対するAmazon.co.jpの商品データを使ったアプリケーションを作ることができる、という仕組みです。何だか面白いものが作れそうな気がしてきますよね。
********には登録IDを入力。
Amazon Standard Item Numberの略で、Amazonで扱っている商品を一意に示すコードのこと。
Copyright © ITmedia, Inc. All Rights Reserved.