- 追加された行はこの色です。
- 削除された行はこの色です。
*ItemSearchのサンプルコード(VB.NET) [#w3357c22]
[[こちらのC#のコード>../../CS/ItemSearch]]をVB.NETに変換したものです。
ここで紹介しているコードは[[こちらのプロキシクラス>../../../ProxyClass]]を使用しています。
ここで紹介しているコードは[[こちらのC#のコード>../../CS/ItemSearch]]をVB.NETに変換したものです。
Amazon.co.jpで商品を検索するサンプルです。TextBoxに検索するキーワードを入れて、DropDownListで検索するカテゴリを指定できます。さらに、BrowseNodeを入力することもできるようになっています。
#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 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" AndAlso _
req.SearchIndex <> "MusicTracks" Then
req.Sort = "salesrank"
End If 'BrowseNode
If TextBox2.Text <> "" Then
req.BrowseNode = TextBox2.Text
End If '新品以外や、Amazon以外の売り手の商品も表示
If req.SearchIndex <> "Blended" AndAlso _
req.SearchIndex <> "MusicTracks" Then
req.Condition = Condition.All
req.ConditionSpecified = True
req.MerchantId = "All"
'利用可能な商品のみ表示
req.Availability = ItemSearchRequestAvailability.Available
req.AvailabilitySpecified = True
End If
Dim isc As New ItemSearch()
'あなたのAccess Key ID
'AWSAccessKeyIdかSubscriptionIdのどちらかを必ず指定する
isc.AWSAccessKeyId = "(あなたのAccessKeyID)"
'あなたのAssociate ID
isc.AssociateTag = "dobonnet-22"
isc.Request = New ItemSearchRequest() {req}
Dim aws As New AWSECommerceService()
'プロキシを通す場合は、次のようにする
'aws.Proxy = new System.Net.WebProxy("localhost", 8080);
Dim res As ItemSearchResponse
Try
'ItemSearchオペレーションを実行し、結果を取得
res = aws.ItemSearch(isc)
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 += res.Items(0).TotalResults + _
" 件見つかりました。<br />" + vbLf
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
Label1.Text += "ASIN : " + i.ASIN + "<br />" + vbLf
'画像を表示
'ResponseGroupにImagesなどが必要
If Not (i.MediumImage Is Nothing) Then
Label1.Text += "<img src=""" + i.MediumImage.URL + _
""" width=""" + _
i.MediumImage.Width.Value.ToString() + _
""" height=""" + _
i.MediumImage.Height.Value.ToString() + _
"""><br />" + vbLf
End If
'クリエーター情報
If Not (i.ItemAttributes.Creator Is Nothing) Then
Dim c As ItemAttributesCreator
For Each c In i.ItemAttributes.Creator
Label1.Text += c.Role + " : " + _
c.Value + "<br />" + vbLf
Next c
End If
'出版社
If Not (i.ItemAttributes.Publisher Is Nothing) Then
Label1.Text += i.ItemAttributes.Publisher + _
"<br />" + vbLf
End If
'価格
'ResponseGroupにItemAttributesなどが必要
If Not (i.ItemAttributes.ListPrice Is Nothing) Then
Label1.Text += "参考価格 : " + _
i.ItemAttributes.ListPrice.FormattedPrice + _
"<br />" + vbLf
End If
'ResponseGroupにOfferFullなどが必要
'実際の価格の表示
If Not (i.Offers Is Nothing) AndAlso _
Not (i.Offers.Offer Is Nothing) Then
Label1.Text += "価格 : <br />" + vbLf
Label1.Text += "<ul>" + vbLf
Dim off As Offer
For Each off In i.Offers.Offer
If Not ([off].OfferListing Is Nothing) Then
Label1.Text += "<ul>" + vbLf
Dim ol As OfferListing
For Each ol In [off].OfferListing
Label1.Text += "<li>" + _
ol.Price.FormattedPrice + vbLf
Next ol
Label1.Text += "</ul>" + vbLf
End If
Next off
Label1.Text += "</ul>" + vbLf
End If
'最安値
If Not (i.OfferSummary Is Nothing) AndAlso _
Not (i.OfferSummary.LowestNewPrice Is Nothing) AndAlso _
Not (i.OfferSummary.LowestNewPrice.FormattedPrice _
Is Nothing) Then
Label1.Text += "新品の最安値 : " + _
i.OfferSummary.LowestNewPrice.FormattedPrice + _
"<br />" + vbLf
End If
'EditorialReview
If Not (i.EditorialReviews Is Nothing) Then
Label1.Text += "エディターレビュー : <br />"
Label1.Text += "<ul>" + vbLf
Dim r As EditorialReview
For Each r In i.EditorialReviews
Label1.Text += "<li>" + r.Source + " : " + _
r.Content + vbLf
Next r
Label1.Text += "</ul>" + vbLf
End If
'カスタマーレビュー
If Not (i.CustomerReviews Is Nothing) Then
Label1.Text += "お勧め度 : " + _
i.CustomerReviews.AverageRating.ToString() + _
"<br />"
Label1.Text += "カスタマーレビュー : <br />"
Label1.Text += "<ul>" + vbLf
Dim r As Review
For Each r In i.CustomerReviews.Review
Label1.Text += "<li>" + r.Summary + vbLf
Next r
Label1.Text += "</ul>" + vbLf
End If
'リストマニア
If Not (i.ListmaniaLists Is Nothing) Then
Label1.Text += "リストマニア : <br />"
Label1.Text += "<ul>" + vbLf
Dim lm As ListmaniaListsListmaniaList
For Each lm In i.ListmaniaLists
Label1.Text += "<li>" + lm.ListName + vbLf
Next lm
Label1.Text += "</ul>" + vbLf
End If
'この商品を買った人はこんな商品も買っています
If Not (i.SimilarProducts Is Nothing) Then
Label1.Text += _
"この商品を買った人はこんな商品も買っています" + _
" : <br />"
Label1.Text += "<ul>" + vbLf
Dim sp As SimilarProductsSimilarProduct
For Each sp In i.SimilarProducts
Label1.Text += "<li>" + sp.Title + vbLf
Next sp
Label1.Text += "</ul>" + vbLf
End If
'曲目リスト
If Not (i.Tracks Is Nothing) Then
Label1.Text += "曲目リスト : <br />"
Label1.Text += "<ul>" + vbLf
Dim td As TracksDisc
For Each td In i.Tracks
Label1.Text += "<li>" + td.Number + vbLf
If Not (td.Track Is Nothing) Then
Label1.Text += "<ul>" + vbLf
Dim tdt As TracksDiscTrack
For Each tdt In td.Track
Label1.Text += "<li>" + tdt.Number + ":" + _
tdt.Value + vbLf
Next tdt
Label1.Text += "</ul>" + vbLf
End If
Next td
Label1.Text += "</ul>" + vbLf
End If
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>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="検索" EnableViewState="False" /><br />
<asp:DropDownList ID="searchIndex" runat="server">
<asp:ListItem Value="Blended">すべて</asp:ListItem>
<asp:ListItem Value="Books">本</asp:ListItem>
<asp:ListItem Value="Classical">クラシック</asp:ListItem>
<asp:ListItem>DVD</asp:ListItem>
<asp:ListItem Value="Electronics">エレクトロニクス</asp:ListItem>
<asp:ListItem Value="ForeignBooks">洋書</asp:ListItem>
<asp:ListItem Value="Hobbies">ホビー</asp:ListItem>
<asp:ListItem Value="Kitchen">ホーム&キッチン</asp:ListItem>
<asp:ListItem Value="Music">音楽</asp:ListItem>
<asp:ListItem Value="MusicTracks">曲名</asp:ListItem>
<asp:ListItem Value="Software">ソフトウェア</asp:ListItem>
<asp:ListItem Value="SportingGoods">スポーツ</asp:ListItem>
<asp:ListItem Value="Toys">おもちゃ</asp:ListItem>
<asp:ListItem>VHS</asp:ListItem>
<asp:ListItem Value="Video">DVD&ビデオ</asp:ListItem>
<asp:ListItem Value="VideoGames">ゲーム</asp:ListItem>
</asp:DropDownList><br />
<label for="TextBox2">BrowseNode : </label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
</div>
</form>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="False">
</asp:Label>
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-10-20 (金) 00:28:23,DOBON!,2006-10-20 (金) 00:28:23,DOBON!)
#pageinfo([[:Category/.NET]] [[:Category/ASP.NET]],2006-10-20 (金) 00:28:23,DOBON!,2006-10-20 (金) 02:18:44,DOBON!)