*ItemLookupのサンプルコード(VB.NET) [#n9f0d8e1] ここで紹介しているコードは[[こちらのプロキシクラス>../../../ProxyClass]]を使用しています。 ここで紹介しているコードは[[こちらのC#のコード>../../CS/ItemLookup]]をVB.NETに変換したものです。 Amazon.co.jpで売られている商品の情報(売り手の名前と価格)を表示するサンプルです。TextBoxに商品のASINを入力します。 #code(vbnet){{ <%@ Page Language="VB" %> <%@ 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 Sub Button1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Dim req As 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"} Dim il As New ItemLookup() 'あなたのAccess Key ID il.AWSAccessKeyId = "(あなたのAccessKeyID)" 'あなたのAssociate ID il.AssociateTag = "dobonnet-22" il.Request = New ItemLookupRequest() {req} Dim aws As New AWSECommerceService() Dim res As ItemLookupResponse Try 'ItemLookupオペレーションを実行し、結果を取得 res = aws.ItemLookup(il) Catch ex As Exception Label1.Text = "エラー:" + Server.HtmlEncode(ex.Message) Return End Try If res Is Nothing OrElse res.Items Is Nothing Then Label1.Text = "結果を取得できませんでした。" Return End If If Not (res.Items(0).Request.Errors Is Nothing) Then Label1.Text = "エラー:" + _ res.Items(0).Request.Errors(0).Message Return End If If res.Items(0).Item Is Nothing Then Label1.Text = "該当する商品が見つかりませんでした。" Return End If '結果を表示 Label1.Text = "" Dim item As Item = res.Items(0).Item(0) Label1.Text += "<b><a href=""" + item.DetailPageURL + """>" + _ item.ItemAttributes.Title + "</a></b><br />" + vbLf '売り手、価格を表示 If Not (item.Offers Is Nothing) AndAlso _ Not (item.Offers.Offer Is Nothing) Then Label1.Text += "<ul>" + vbLf Dim o As Offer For Each o In item.Offers.Offer '売り手の名前 If Not (o.Seller Is Nothing) Then Label1.Text += "<li><b>" + _ o.Seller.Nickname + "</b>" + vbLf Label1.Text += "<br />ID : " + _ o.Seller.SellerId + vbLf Else 'SellerがNULLのときはAmazonと判断する Label1.Text += "<li><b>Amazon</b>" + vbLf End If '価格 If Not (o.OfferListing Is Nothing) Then Label1.Text += "<ul>" + vbLf Dim ol As OfferListing For Each ol In o.OfferListing Label1.Text += "<li>価格 : " + _ ol.Price.FormattedPrice + "<br>" Label1.Text += "ID : " + _ ol.OfferListingId + "<br>" Next ol Label1.Text += "</ul>" + vbLf End If Next o Label1.Text += "</ul>" + vbLf End If End Sub </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:36:19,DOBON!,2006-10-20 (金) 02:18:29,DOBON!) |