ファジィってやつですか?
Amazon Product Advertising APIで商品を検索するとXMLを返してくるんだけど、なんか変だ。
Blended 検索結果 (43 件)(1 / 17 ページ)
1ページに表示出来る数は10件。
でも、たまに10件以上返ってくる。
上の奴だと43件だから5ページあるはずなのに、何故か17ページと表示される。
実際は17ページもあるはずなく、5ページしかなかった。
ページは信用ならんのかの?
ヒット件数も若干ずれてるなぁ…
どうしたものか……
Amazon Product Advertising APIで商品を検索するとXMLを返してくるんだけど、なんか変だ。
1ページに表示出来る数は10件。
でも、たまに10件以上返ってくる。
上の奴だと43件だから5ページあるはずなのに、何故か17ページと表示される。
実際は17ページもあるはずなく、5ページしかなかった。
ページは信用ならんのかの?
ヒット件数も若干ずれてるなぁ…
どうしたものか……
ちょろちょろっとPHPの入門書を見ながら作ってみたテスト。
XMLともにらめっこしないといけないとは…
上のHTML
<form action="http://www.dazzlingworld2.com/uploads/2009/07/amazon.php" method="post"> <input style="width: 200px;" name="Keywords" type="text" /> <input name="button" type="submit" value="検索" /> <br /> <label><input checked="checked" name="SearchIndex" type="radio" value="Blended" />すべて</label> <label><input name="SearchIndex" type="radio" value="Books" />和書</label> <label><input name="SearchIndex" type="radio" value="ForeignBooks" />洋書</label> <label><input name="SearchIndex" type="radio" value="Electronics" />エレクトロニクス</label> <label><input name="SearchIndex" type="radio" value="Kitchen" />ホーム&キッチン</label> <label><input name="SearchIndex" type="radio" value="Music" />音楽</label> <label><input name="SearchIndex" type="radio" value="MusicTracks" />曲名</label> <label><input name="SearchIndex" type="radio" value="Classical" />クラシック</label> <label><input name="SearchIndex" type="radio" value="DVD" />DVD</label> <label><input name="SearchIndex" type="radio" value="VHS" />VHS</label> <label><input name="SearchIndex" type="radio" value="Video" />ビデオ</label> <label><input name="SearchIndex" type="radio" value="Software" />ソフトウェア</label> <label><input name="SearchIndex" type="radio" value="VideoGames" />ゲーム</label> <label><input name="SearchIndex" type="radio" value="Toys" />おもちゃ</label> <label><input name="SearchIndex" type="radio" value="Hobbies" />ホビー</label> <label><input name="SearchIndex" type="radio" value="SportingGoods" />スポーツ&アウトドア</label> <label><input name="SearchIndex" type="radio" value="HealthPersonalCare" />ヘルス&ビューティー</label> <label><input name="SearchIndex" type="radio" value="Watches" />時計</label> <label><input name="SearchIndex" type="radio" value="Baby" />ベビー&マタニティ</label> <label><input name="SearchIndex" type="radio" value="Apparel" />アパレル</label> <label><input name="SearchIndex" type="radio" value="asin" />ASIN / ISBN番号</label> </form>
amazon.php
<?php
require_once("Services/Amazon.php");
$option = array(
"subscription_id" => [Subscription_ID],
"secret_key" => [Secret_KEY],
"associate_tag" => [Associate_tag],
"locale" => "JP"
);
$keywords = $_POST['Keywords'];
$SearchIndex = $_POST['SearchIndex'];
$amazon = new Services_Amazon($option["subscription_id"], $option["secret_key"], $option["associate_tag"]);
$amazon->setLocale($option["locale"]);
$item_list = $amazon->ItemSearch($SearchIndex, array("Keywords" => $keywords, "ResponseGroup" => 'Images,ItemAttributes'));
foreach($item_list["Item"] as $key => $value) {
$title = $value["ItemAttributes"]["Title"];
$DetailPageURL = $value["DetailPageURL"];
$img_src = $value["MediumImage"]["URL"];
$img_height = $value["MediumImage"]["Height"]["_content"];
$img_width = $value["MediumImage"]["Width"]["_content"];
if($img_src != "") {
print('<a href="'.$DetailPageURL.'">');
print('<img src="'.$img_src.'" height="'.$img_height.'" width="'.$img_width.'" alt="'.$title.'" title="'.$title.'" />');
print('</a>');
}
}($item_list);
?>
PHPで簡単にamazonのAPIを使えるのがPEARにあったので、インストールしてみた。
PEAR::Services_Amazon
先にXML_Serializerをインストールしないといけないみたいです。
# pear install -a channel://pear.php.net/XML_Serializer-0.18.0
# pear install -a Services_Amazon-0.8.0
簡単とは言ってもドキュメントは英語…
英語…orz