*SimilarityLookupのサンプルコード(VB.NET) [#i4533692]

[[こちらのC#のコード>../../CS/SimilarityLookup]]を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 SimilarityLookupRequest()
        '類似した商品を調べたい商品のASINを指定
        req.ItemId = New String() {TextBox1.Text}
   
        Dim sl As New SimilarityLookup()
        'あなたのAccess Key ID
        sl.AWSAccessKeyId = "(あなたのAccessKeyID)"
        'あなたのAssociate ID
        sl.AssociateTag = "dobonnet-22"
        sl.Request = New SimilarityLookupRequest() {req}
   
        Dim aws As New AWSECommerceService()
        Dim res As SimilarityLookupResponse
        Try
            'SimilarityLookupオペレーションを実行し、結果を取得
            res = aws.SimilarityLookup(sl)
        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 = ""
        Label1.Text += _
            "この商品を買った人はこんな商品も買っています" + " :<br />"
        Label1.Text += "<ul>" + vbLf
        Dim i As Item
        For Each i In res.Items(0).Item
            Label1.Text += "<li><b><a href=""" + i.DetailPageURL + _
                """>" + i.ItemAttributes.Title + _
                "</a></b><br />" + vbLf
        Next i
        Label1.Text += "</ul>" + vbLf
    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="送信" /><br />
      </div>
    </form>
    <br />
    <asp:Label ID="Label1" runat="server" EnableViewState="False">
    </asp:Label>
</body>
</html>
}}

//これより下は編集しないでください
#pageinfo(,2006-10-20 (金) 01:53:42,DOBON!,2006-10-20 (金) 01:53:42,DOBON!)
[ トップ ]   [ 新規 | 子ページ作成 | 一覧 | 単語検索 | 最終更新 | ヘルプ ]