DoboWiki
Top
> 自由区/Webサービス紹介/Amazon E-Commerce Service/Code/VB.NET/ItemSearch をテンプレートにして作成
自由区/Webサービス紹介/Amazon E-Commerce Service/Code/VB.NET/ItemSearch をテンプレートにして作成
開始行:
*ItemSearchのサンプルコード(VB.NET) [#w3357c22]
ここで紹介しているコードは[[こちらのプロキシクラス>../../...
ここで紹介しているコードは[[こちらのC#のコード>../../CS/I...
Amazon.co.jpで商品を検索するサンプルです。TextBoxに検索す...
#code(vbnet){{
<%@ Page Language="VB" %>
<%@ Import Namespace="Amazon.jp.v20060913" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"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 = ItemSearchRequestAvailabil...
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",...
Dim res As ItemSearchResponse
Try
'ItemSearchオペレーションを実行し、結果を取得
res = aws.ItemSearch(isc)
Catch ex As Exception
Label1.Text = "エラー:" + Server.HtmlEncode(...
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) T...
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.ItemAttribute...
"</a></b><br />" + vbLf
Label1.Text += "ASIN : " + i.ASIN + "<br />" ...
'画像を表示
'ResponseGroupにImagesなどが必要
If Not (i.MediumImage Is Nothing) Then
Label1.Text += "<img src=""" + i.MediumIm...
""" width=""" + _
i.MediumImage.Width.Value.ToString() ...
""" height=""" + _
i.MediumImage.Height.Value.ToString()...
"""><br />" + vbLf
End If
'クリエーター情報
If Not (i.ItemAttributes.Creator Is Nothing) ...
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...
Label1.Text += i.ItemAttributes.Publisher...
"<br />" + vbLf
End If
'価格
'ResponseGroupにItemAttributesなどが必要
If Not (i.ItemAttributes.ListPrice Is Nothing...
Label1.Text += "参考価格 : " + _
i.ItemAttributes.ListPrice.FormattedP...
"<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...
Label1.Text += "<ul>" + vbLf
Dim ol As OfferListing
For Each ol In [off].OfferListing
Label1.Text += "<li>" + _
ol.Price.FormattedPrice +...
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 Not...
Not (i.OfferSummary.LowestNewPrice.Format...
Is Nothing) Then
Label1.Text += "新品の最安値 : " + _
i.OfferSummary.LowestNewPrice.Formatt...
"<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.ToStr...
"<br />"
Label1.Text += "カスタマーレビュー : <br ...
Label1.Text += "<ul>" + vbLf
Dim r As Review
For Each r In i.CustomerReviews.Review
Label1.Text += "<li>" + r.Summary + v...
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 +...
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 + v...
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.N...
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:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="検索" EnableViewState="False" /><br />
<asp:DropDownList ID="searchIndex" runat="server">
<asp:ListItem Value="Blended">すべて</asp:Lis...
<asp:ListItem Value="Books">本</asp:ListItem>
<asp:ListItem Value="Classical">クラシック</a...
<asp:ListItem>DVD</asp:ListItem>
<asp:ListItem Value="Electronics">エレクトロ...
<asp:ListItem Value="ForeignBooks">洋書</asp:...
<asp:ListItem Value="Hobbies">ホビー</asp:Lis...
<asp:ListItem Value="Kitchen">ホーム&キッチ...
<asp:ListItem Value="Music">音楽</asp:ListItem>
<asp:ListItem Value="MusicTracks">曲名</asp:L...
<asp:ListItem Value="Software">ソフトウェア</...
<asp:ListItem Value="SportingGoods">スポーツ<...
<asp:ListItem Value="Toys">おもちゃ</asp:List...
<asp:ListItem>VHS</asp:ListItem>
<asp:ListItem Value="Video">DVD&ビデオ</asp:...
<asp:ListItem Value="VideoGames">ゲーム</asp:...
</asp:DropDownList><br />
<label for="TextBox2">BrowseNode : </label>
<asp:TextBox ID="TextBox2" runat="server"></asp:T...
</div>
</form>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState...
</asp:Label>
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo([[:Category/.NET]] [[:Category/ASP.NET]],2006-1...
終了行:
*ItemSearchのサンプルコード(VB.NET) [#w3357c22]
ここで紹介しているコードは[[こちらのプロキシクラス>../../...
ここで紹介しているコードは[[こちらのC#のコード>../../CS/I...
Amazon.co.jpで商品を検索するサンプルです。TextBoxに検索す...
#code(vbnet){{
<%@ Page Language="VB" %>
<%@ Import Namespace="Amazon.jp.v20060913" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"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 = ItemSearchRequestAvailabil...
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",...
Dim res As ItemSearchResponse
Try
'ItemSearchオペレーションを実行し、結果を取得
res = aws.ItemSearch(isc)
Catch ex As Exception
Label1.Text = "エラー:" + Server.HtmlEncode(...
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) T...
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.ItemAttribute...
"</a></b><br />" + vbLf
Label1.Text += "ASIN : " + i.ASIN + "<br />" ...
'画像を表示
'ResponseGroupにImagesなどが必要
If Not (i.MediumImage Is Nothing) Then
Label1.Text += "<img src=""" + i.MediumIm...
""" width=""" + _
i.MediumImage.Width.Value.ToString() ...
""" height=""" + _
i.MediumImage.Height.Value.ToString()...
"""><br />" + vbLf
End If
'クリエーター情報
If Not (i.ItemAttributes.Creator Is Nothing) ...
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...
Label1.Text += i.ItemAttributes.Publisher...
"<br />" + vbLf
End If
'価格
'ResponseGroupにItemAttributesなどが必要
If Not (i.ItemAttributes.ListPrice Is Nothing...
Label1.Text += "参考価格 : " + _
i.ItemAttributes.ListPrice.FormattedP...
"<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...
Label1.Text += "<ul>" + vbLf
Dim ol As OfferListing
For Each ol In [off].OfferListing
Label1.Text += "<li>" + _
ol.Price.FormattedPrice +...
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 Not...
Not (i.OfferSummary.LowestNewPrice.Format...
Is Nothing) Then
Label1.Text += "新品の最安値 : " + _
i.OfferSummary.LowestNewPrice.Formatt...
"<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.ToStr...
"<br />"
Label1.Text += "カスタマーレビュー : <br ...
Label1.Text += "<ul>" + vbLf
Dim r As Review
For Each r In i.CustomerReviews.Review
Label1.Text += "<li>" + r.Summary + v...
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 +...
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 + v...
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.N...
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:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="検索" EnableViewState="False" /><br />
<asp:DropDownList ID="searchIndex" runat="server">
<asp:ListItem Value="Blended">すべて</asp:Lis...
<asp:ListItem Value="Books">本</asp:ListItem>
<asp:ListItem Value="Classical">クラシック</a...
<asp:ListItem>DVD</asp:ListItem>
<asp:ListItem Value="Electronics">エレクトロ...
<asp:ListItem Value="ForeignBooks">洋書</asp:...
<asp:ListItem Value="Hobbies">ホビー</asp:Lis...
<asp:ListItem Value="Kitchen">ホーム&キッチ...
<asp:ListItem Value="Music">音楽</asp:ListItem>
<asp:ListItem Value="MusicTracks">曲名</asp:L...
<asp:ListItem Value="Software">ソフトウェア</...
<asp:ListItem Value="SportingGoods">スポーツ<...
<asp:ListItem Value="Toys">おもちゃ</asp:List...
<asp:ListItem>VHS</asp:ListItem>
<asp:ListItem Value="Video">DVD&ビデオ</asp:...
<asp:ListItem Value="VideoGames">ゲーム</asp:...
</asp:DropDownList><br />
<label for="TextBox2">BrowseNode : </label>
<asp:TextBox ID="TextBox2" runat="server"></asp:T...
</div>
</form>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState...
</asp:Label>
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo([[:Category/.NET]] [[:Category/ASP.NET]],2006-1...
ページ名:
▲
▼
[
トップ
] [
新規
|
子ページ作成
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]