DoboWiki
Top
> 自由区/Webサービス紹介/Amazon E-Commerce Service/Code/CS/ItemSearch をテンプレートにして作成
自由区/Webサービス紹介/Amazon E-Commerce Service/Code/CS/ItemSearch をテンプレートにして作成
開始行:
*ItemSearchのサンプルコード(C#) [#q7b0ea10]
ここで紹介しているコードは[[こちらのプロキシクラス>../../...
Amazon.co.jpで商品を検索するサンプルです。TextBoxに検索す...
#code(csharp){{
<%@ Page Language="C#" %>
<%@ Import Namespace="Amazon.jp.v20060913" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs...
{
ItemSearchRequest req = new ItemSearchRequest();
//検索するストアのインデックスを指定する(必須)
req.SearchIndex = searchIndex.SelectedValue;
//検索する語句を指定
req.Keywords = TextBox1.Text;
//取得するデータの種類(範囲)を指定
req.ResponseGroup = new string[] {
"Small","ItemAttributes", "OfferFull",
"Images", "Reviews", "EditorialReview",
"ListmaniaLists", "Similarities", "Tracks"};
//ページを指定する。1-400まで。1ページ10の結果ま...
req.ItemPage = "1";
//並び替え方
//SearchIndexや地域によって異なる
if (req.SearchIndex != "Blended" &&
req.SearchIndex != "MusicTracks")
req.Sort = "salesrank";
//BrowseNode
if (TextBox2.Text != "")
req.BrowseNode = TextBox2.Text;
//新品以外や、Amazon以外の売り手の商品も表示
if (req.SearchIndex != "Blended" &&
req.SearchIndex != "MusicTracks")
{
req.Condition = Condition.All;
req.ConditionSpecified = true;
req.MerchantId = "All";
//利用可能な商品のみ表示
req.Availability = ItemSearchRequestAvailabil...
req.AvailabilitySpecified = true;
}
ItemSearch isc = new ItemSearch();
//あなたのAccess Key ID
//AWSAccessKeyIdかSubscriptionIdのどちらかを必ず...
isc.AWSAccessKeyId = "(あなたのAccessKeyID)";
//あなたのAssociate ID
isc.AssociateTag = "dobonnet-22";
isc.Request = new ItemSearchRequest[] { req };
AWSECommerceService aws = new AWSECommerceService...
//プロキシを通す場合は、次のようにする
//aws.Proxy = new System.Net.WebProxy("localhost"...
ItemSearchResponse res;
try
{
//ItemSearchオペレーションを実行し、結果を取得
res = aws.ItemSearch(isc);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + Server.HtmlEncode(...
return;
}
if (res == null || res.Items == null)
{
Label1.Text = "結果を取得できませんでした。";
return;
}
if (res.Items[0].Request.Errors != null)
{
Label1.Text = "エラー:" +
res.Items[0].Request.Errors[0].Message;
return;
}
if (res.Items[0].Item == null)
{
Label1.Text = "該当する商品が見つかりませんで...
return;
}
//結果を表示
Label1.Text = "";
Label1.Text += res.Items[0].TotalResults +
" 件見つかりました。<br />\n";
Label1.Text += "<ul>\n";
foreach (Item i in res.Items[0].Item)
{
//タイトル
Label1.Text += "<li><b><a href=\"" + i.Detail...
i.ItemAttributes.Title + "</a></b><br />\...
Label1.Text += "ASIN : " + i.ASIN + "<br />\n";
//画像を表示
//ResponseGroupにImagesなどが必要
if (i.MediumImage != null)
Label1.Text += "<img src=\"" + i.MediumIm...
"\" width=\"" + i.MediumImage.Width.V...
"\" height=\"" + i.MediumImage.Height...
"\"><br />\n";
//クリエーター情報
if (i.ItemAttributes.Creator != null)
{
foreach (ItemAttributesCreator c in i.Ite...
{
Label1.Text += c.Role + " : " + c.Val...
}
}
//出版社
if (i.ItemAttributes.Publisher != null)
Label1.Text += i.ItemAttributes.Publisher...
//価格
//ResponseGroupにItemAttributesなどが必要
if (i.ItemAttributes.ListPrice != null)
Label1.Text += "参考価格 : " +
i.ItemAttributes.ListPrice.FormattedP...
//ResponseGroupにOfferFullなどが必要
//実際の価格の表示
if (i.Offers != null && i.Offers.Offer != null)
{
Label1.Text += "価格 : <br />\n";
Label1.Text += "<ul>\n";
foreach (Offer off in i.Offers.Offer)
{
if (off.OfferListing != null)
{
Label1.Text += "<ul>\n";
foreach (OfferListing ol in off.O...
{
Label1.Text +=
"<li>" + ol.Price.Formatt...
}
Label1.Text += "</ul>\n";
}
}
Label1.Text += "</ul>\n";
}
//最安値
if (i.OfferSummary != null &&
i.OfferSummary.LowestNewPrice != null &&
i.OfferSummary.LowestNewPrice.FormattedPr...
Label1.Text += "新品の最安値 : " +
i.OfferSummary.LowestNewPrice.Formatt...
"<br />\n";
//EditorialReview
if (i.EditorialReviews != null)
{
Label1.Text += "エディターレビュー : <br ...
Label1.Text += "<ul>\n";
foreach (EditorialReview r in i.Editorial...
{
Label1.Text += "<li>" + r.Source + " ...
+ r.Content + "\n";
}
Label1.Text += "</ul>\n";
}
//カスタマーレビュー
if (i.CustomerReviews != null)
{
Label1.Text += "お勧め度 : " +
i.CustomerReviews.AverageRating.ToStr...
"<br />";
Label1.Text += "カスタマーレビュー : <br ...
Label1.Text += "<ul>\n";
foreach (Review r in i.CustomerReviews.Re...
{
Label1.Text += "<li>" + r.Summary + "...
}
Label1.Text += "</ul>\n";
}
//リストマニア
if (i.ListmaniaLists != null)
{
Label1.Text += "リストマニア : <br />";
Label1.Text += "<ul>\n";
foreach (ListmaniaListsListmaniaList lm i...
{
Label1.Text += "<li>" + lm.ListName +...
}
Label1.Text += "</ul>\n";
}
//この商品を買った人はこんな商品も買っています
if (i.SimilarProducts != null)
{
Label1.Text += "この商品を買った人はこん...
" : <br />";
Label1.Text += "<ul>\n";
foreach (SimilarProductsSimilarProduct sp...
{
Label1.Text += "<li>" + sp.Title + "\...
}
Label1.Text += "</ul>\n";
}
//曲目リスト
if (i.Tracks != null)
{
Label1.Text += "曲目リスト : <br />";
Label1.Text += "<ul>\n";
foreach (TracksDisc td in i.Tracks)
{
Label1.Text += "<li>" + td.Number + "...
if (td.Track != null)
{
Label1.Text += "<ul>\n";
foreach (TracksDiscTrack tdt in t...
Label1.Text +=
"<li>" + tdt.Number + ":"...
Label1.Text += "</ul>\n";
}
}
Label1.Text += "</ul>\n";
}
}
Label1.Text += "</ul>\n";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Amazon商品検索</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="検索" EnableViewState="False" /><br />
<asp:DropDownList ID="searchIndex" runat="server">
<asp:ListItem Value="Blended">すべて</asp:Lis...
<asp:ListItem Value="Books">本</asp:ListItem>
<asp:ListItem Value="Classical">クラシック</a...
<asp:ListItem>DVD</asp:ListItem>
<asp:ListItem Value="Electronics">エレクトロ...
<asp:ListItem Value="ForeignBooks">洋書</asp:...
<asp:ListItem Value="Hobbies">ホビー</asp:Lis...
<asp:ListItem Value="Kitchen">ホーム&キッチ...
<asp:ListItem Value="Music">音楽</asp:ListItem>
<asp:ListItem Value="MusicTracks">曲名</asp:L...
<asp:ListItem Value="Software">ソフトウェア</...
<asp:ListItem Value="SportingGoods">スポーツ<...
<asp:ListItem Value="Toys">おもちゃ</asp:List...
<asp:ListItem>VHS</asp:ListItem>
<asp:ListItem Value="Video">DVD&ビデオ</asp:...
<asp:ListItem Value="VideoGames">ゲーム</asp:...
</asp:DropDownList><br />
<label for="TextBox2">BrowseNode : </label>
<asp:TextBox ID="TextBox2" runat="server"></asp:T...
</div>
</form>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState...
</asp:Label>
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo([[:Category/.NET]] [[:Category/ASP.NET]],2006-1...
終了行:
*ItemSearchのサンプルコード(C#) [#q7b0ea10]
ここで紹介しているコードは[[こちらのプロキシクラス>../../...
Amazon.co.jpで商品を検索するサンプルです。TextBoxに検索す...
#code(csharp){{
<%@ Page Language="C#" %>
<%@ Import Namespace="Amazon.jp.v20060913" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs...
{
ItemSearchRequest req = new ItemSearchRequest();
//検索するストアのインデックスを指定する(必須)
req.SearchIndex = searchIndex.SelectedValue;
//検索する語句を指定
req.Keywords = TextBox1.Text;
//取得するデータの種類(範囲)を指定
req.ResponseGroup = new string[] {
"Small","ItemAttributes", "OfferFull",
"Images", "Reviews", "EditorialReview",
"ListmaniaLists", "Similarities", "Tracks"};
//ページを指定する。1-400まで。1ページ10の結果ま...
req.ItemPage = "1";
//並び替え方
//SearchIndexや地域によって異なる
if (req.SearchIndex != "Blended" &&
req.SearchIndex != "MusicTracks")
req.Sort = "salesrank";
//BrowseNode
if (TextBox2.Text != "")
req.BrowseNode = TextBox2.Text;
//新品以外や、Amazon以外の売り手の商品も表示
if (req.SearchIndex != "Blended" &&
req.SearchIndex != "MusicTracks")
{
req.Condition = Condition.All;
req.ConditionSpecified = true;
req.MerchantId = "All";
//利用可能な商品のみ表示
req.Availability = ItemSearchRequestAvailabil...
req.AvailabilitySpecified = true;
}
ItemSearch isc = new ItemSearch();
//あなたのAccess Key ID
//AWSAccessKeyIdかSubscriptionIdのどちらかを必ず...
isc.AWSAccessKeyId = "(あなたのAccessKeyID)";
//あなたのAssociate ID
isc.AssociateTag = "dobonnet-22";
isc.Request = new ItemSearchRequest[] { req };
AWSECommerceService aws = new AWSECommerceService...
//プロキシを通す場合は、次のようにする
//aws.Proxy = new System.Net.WebProxy("localhost"...
ItemSearchResponse res;
try
{
//ItemSearchオペレーションを実行し、結果を取得
res = aws.ItemSearch(isc);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + Server.HtmlEncode(...
return;
}
if (res == null || res.Items == null)
{
Label1.Text = "結果を取得できませんでした。";
return;
}
if (res.Items[0].Request.Errors != null)
{
Label1.Text = "エラー:" +
res.Items[0].Request.Errors[0].Message;
return;
}
if (res.Items[0].Item == null)
{
Label1.Text = "該当する商品が見つかりませんで...
return;
}
//結果を表示
Label1.Text = "";
Label1.Text += res.Items[0].TotalResults +
" 件見つかりました。<br />\n";
Label1.Text += "<ul>\n";
foreach (Item i in res.Items[0].Item)
{
//タイトル
Label1.Text += "<li><b><a href=\"" + i.Detail...
i.ItemAttributes.Title + "</a></b><br />\...
Label1.Text += "ASIN : " + i.ASIN + "<br />\n";
//画像を表示
//ResponseGroupにImagesなどが必要
if (i.MediumImage != null)
Label1.Text += "<img src=\"" + i.MediumIm...
"\" width=\"" + i.MediumImage.Width.V...
"\" height=\"" + i.MediumImage.Height...
"\"><br />\n";
//クリエーター情報
if (i.ItemAttributes.Creator != null)
{
foreach (ItemAttributesCreator c in i.Ite...
{
Label1.Text += c.Role + " : " + c.Val...
}
}
//出版社
if (i.ItemAttributes.Publisher != null)
Label1.Text += i.ItemAttributes.Publisher...
//価格
//ResponseGroupにItemAttributesなどが必要
if (i.ItemAttributes.ListPrice != null)
Label1.Text += "参考価格 : " +
i.ItemAttributes.ListPrice.FormattedP...
//ResponseGroupにOfferFullなどが必要
//実際の価格の表示
if (i.Offers != null && i.Offers.Offer != null)
{
Label1.Text += "価格 : <br />\n";
Label1.Text += "<ul>\n";
foreach (Offer off in i.Offers.Offer)
{
if (off.OfferListing != null)
{
Label1.Text += "<ul>\n";
foreach (OfferListing ol in off.O...
{
Label1.Text +=
"<li>" + ol.Price.Formatt...
}
Label1.Text += "</ul>\n";
}
}
Label1.Text += "</ul>\n";
}
//最安値
if (i.OfferSummary != null &&
i.OfferSummary.LowestNewPrice != null &&
i.OfferSummary.LowestNewPrice.FormattedPr...
Label1.Text += "新品の最安値 : " +
i.OfferSummary.LowestNewPrice.Formatt...
"<br />\n";
//EditorialReview
if (i.EditorialReviews != null)
{
Label1.Text += "エディターレビュー : <br ...
Label1.Text += "<ul>\n";
foreach (EditorialReview r in i.Editorial...
{
Label1.Text += "<li>" + r.Source + " ...
+ r.Content + "\n";
}
Label1.Text += "</ul>\n";
}
//カスタマーレビュー
if (i.CustomerReviews != null)
{
Label1.Text += "お勧め度 : " +
i.CustomerReviews.AverageRating.ToStr...
"<br />";
Label1.Text += "カスタマーレビュー : <br ...
Label1.Text += "<ul>\n";
foreach (Review r in i.CustomerReviews.Re...
{
Label1.Text += "<li>" + r.Summary + "...
}
Label1.Text += "</ul>\n";
}
//リストマニア
if (i.ListmaniaLists != null)
{
Label1.Text += "リストマニア : <br />";
Label1.Text += "<ul>\n";
foreach (ListmaniaListsListmaniaList lm i...
{
Label1.Text += "<li>" + lm.ListName +...
}
Label1.Text += "</ul>\n";
}
//この商品を買った人はこんな商品も買っています
if (i.SimilarProducts != null)
{
Label1.Text += "この商品を買った人はこん...
" : <br />";
Label1.Text += "<ul>\n";
foreach (SimilarProductsSimilarProduct sp...
{
Label1.Text += "<li>" + sp.Title + "\...
}
Label1.Text += "</ul>\n";
}
//曲目リスト
if (i.Tracks != null)
{
Label1.Text += "曲目リスト : <br />";
Label1.Text += "<ul>\n";
foreach (TracksDisc td in i.Tracks)
{
Label1.Text += "<li>" + td.Number + "...
if (td.Track != null)
{
Label1.Text += "<ul>\n";
foreach (TracksDiscTrack tdt in t...
Label1.Text +=
"<li>" + tdt.Number + ":"...
Label1.Text += "</ul>\n";
}
}
Label1.Text += "</ul>\n";
}
}
Label1.Text += "</ul>\n";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Amazon商品検索</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="検索" EnableViewState="False" /><br />
<asp:DropDownList ID="searchIndex" runat="server">
<asp:ListItem Value="Blended">すべて</asp:Lis...
<asp:ListItem Value="Books">本</asp:ListItem>
<asp:ListItem Value="Classical">クラシック</a...
<asp:ListItem>DVD</asp:ListItem>
<asp:ListItem Value="Electronics">エレクトロ...
<asp:ListItem Value="ForeignBooks">洋書</asp:...
<asp:ListItem Value="Hobbies">ホビー</asp:Lis...
<asp:ListItem Value="Kitchen">ホーム&キッチ...
<asp:ListItem Value="Music">音楽</asp:ListItem>
<asp:ListItem Value="MusicTracks">曲名</asp:L...
<asp:ListItem Value="Software">ソフトウェア</...
<asp:ListItem Value="SportingGoods">スポーツ<...
<asp:ListItem Value="Toys">おもちゃ</asp:List...
<asp:ListItem>VHS</asp:ListItem>
<asp:ListItem Value="Video">DVD&ビデオ</asp:...
<asp:ListItem Value="VideoGames">ゲーム</asp:...
</asp:DropDownList><br />
<label for="TextBox2">BrowseNode : </label>
<asp:TextBox ID="TextBox2" runat="server"></asp:T...
</div>
</form>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState...
</asp:Label>
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo([[:Category/.NET]] [[:Category/ASP.NET]],2006-1...
ページ名:
▲
▼
[
トップ
] [
新規
|
子ページ作成
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]