- 追加された行はこの色です。
- 削除された行はこの色です。
*ItemLookupのサンプルコード(C#) [#ace9f3e2]
ここで紹介しているコードは[[こちらのプロキシクラス>../../../ProxyClass]]を使用しています。
Amazon.co.jpで売られている商品の情報(売り手の名前と価格)を表示するサンプルです。TextBoxに商品のASINを入力します。
#code(csharp){{
<%@ Page Language="C#" %>
<%@ Import Namespace="Amazon.jp.v20060913" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
ItemLookupRequest req = new ItemLookupRequest();
//商品のASINを指定する
req.ItemId = new string[] { TextBox1.Text };
//ItemIdにJANを指定するためには、次のようにする
//req.IdType = ItemLookupRequestIdType.EAN;
//Amazon以外の売り手、新品以外の情報も取得する
req.Condition = Condition.All;
req.ConditionSpecified = true;
req.MerchantId = "All";
req.ResponseGroup = new string[] { "Small", "OfferFull" };
ItemLookup il = new ItemLookup();
//あなたのAccess Key ID
il.AWSAccessKeyId = "(あなたのAccessKeyID)";
//あなたのAssociate ID
il.AssociateTag = "dobonnet-22";
il.Request = new ItemLookupRequest[] { req };
AWSECommerceService aws = new AWSECommerceService();
ItemLookupResponse res;
try
{
//ItemLookupオペレーションを実行し、結果を取得
res = aws.ItemLookup(il);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + Server.HtmlEncode(ex.Message);
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 = "";
Item item = res.Items[0].Item[0];
Label1.Text += "<b><a href=\"" + item.DetailPageURL + "\">" +
item.ItemAttributes.Title + "</a></b><br />\n";
//売り手、価格を表示
if (item.Offers != null && item.Offers.Offer != null)
{
Label1.Text += "<ul>\n";
foreach (Offer o in item.Offers.Offer)
{
//売り手の名前
if (o.Seller != null)
{
Label1.Text += "<li><b>" + o.Seller.Nickname +
"</b>\n";
Label1.Text += "<br />ID : " + o.Seller.SellerId +
"\n";
}
else
{
//SellerがNULLのときはAmazonと判断する
Label1.Text += "<li><b>Amazon</b>\n";
}
//価格
if (o.OfferListing != null)
{
Label1.Text += "<ul>\n";
foreach (OfferListing ol in o.OfferListing)
{
Label1.Text += "<li>価格 : " +
ol.Price.FormattedPrice + "<br>";
Label1.Text += "ID : " +
ol.OfferListingId + "<br>";
}
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>
<label for="TextBox1">ASIN : </label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="送信" EnableViewState="False" /><br />
<br />
</div>
</form>
<asp:Label ID="Label1" runat="server" EnableViewState="False">
</asp:Label>
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-10-20 (金) 00:33:51,DOBON!,2006-10-20 (金) 02:13:55,DOBON!)
#pageinfo([[:Category/.NET]] [[:Category/ASP.NET]],2006-10-20 (金) 00:33:51,DOBON!,2006-10-20 (金) 02:13:55,DOBON!)