*SimilarityLookupのサンプルコード(C#) [#i60028fd] ここで紹介しているコードは[[こちらのプロキシクラス>../../../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) { SimilarityLookupRequest req = new SimilarityLookupRequest(); //類似した商品を調べたい商品のASINを指定 req.ItemId = new string[] { TextBox1.Text }; SimilarityLookup sl = new SimilarityLookup(); //あなたのAccess Key ID sl.AWSAccessKeyId = "(あなたのAccessKeyID)"; //あなたのAssociate ID sl.AssociateTag = "dobonnet-22"; sl.Request = new SimilarityLookupRequest[] { req }; AWSECommerceService aws = new AWSECommerceService(); SimilarityLookupResponse res; try { //SimilarityLookupオペレーションを実行し、結果を取得 res = aws.SimilarityLookup(sl); } 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 = ""; Label1.Text += "この商品を買った人はこんな商品も買っています" + " :<br />"; Label1.Text += "<ul>\n"; foreach (Item i in res.Items[0].Item) { Label1.Text += "<li><b><a href=\"" + i.DetailPageURL + "\">" + i.ItemAttributes.Title + "</a></b><br />\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="送信" /><br /> </div> </form> <br /> <asp:Label ID="Label1" runat="server" EnableViewState="False"> </asp:Label> </body> </html> }} //これより下は編集しないでください #pageinfo(,2006-10-20 (金) 01:53:33,DOBON!,2006-10-20 (金) 02:16:01,DOBON!) |