前提・実現したいこと
Amazon Product Advertising API を用いて、
商品のASINから商品の説明を取得しようとしています。
メーカーの記載しているものではなく、Amazonが記載しているものです。
例えば、お〜いお茶の場合
以下の部分です。
text
1商品の説明 2サイズ:1) 525ml×24本 3商品紹介 4香り高く、まろやかで味わい深い緑茶飲料です。 5 6■お~いお茶“4つの鮮度"へのこだわり 71鮮度茶葉:「お~いお茶専用茶葉」を使用し、加工時間を約半分に短縮 82鮮度抽出:抽出前に茶葉を温めて香りを閉じ込めて抽出 93鮮度充填:お茶に含まれる酸素量を0.0003%以下に抑制し、酸素による味の変化を防止 104鮮度を守る新型容器 「新・鮮度ボトル」採用 11 12原材料・成分 13緑茶(日本)/ビタミンC
Amazon APIで返すことのできる項目のResponse Groupsの中から「商品の説明」に該当するのはPromotionSummaryになるのではないかという仮定のもと進めていますが、別のResponse Groupが「商品の説明」に該当する可能性もあるのではないかと考えています。
発生している問題・エラーメッセージ
ItemLookupのページでAssociateTagや商品のASINを入力し、
取得したい情報としてImageを選択すると、Java・PHP、Ruby on Railsで
コードスニペットが表示されます。
開発はPythonで行なっているため、Javaで表示されたものをPythonに書き換える際にJavaでは以下の部分をどう書き換えれば良いかわかりません。
params.put("Service", "AWSECommerceService"); params.put("Operation", "ItemSearch"); params.put("AWSAccessKeyId", ""); params.put("AssociateTag", ""); params.put("SearchIndex", "All"); params.put("ResponseGroup", "PromotionSummary");
該当のソースコード
ItemLookupのページでAssociateTagや商品のASINを入力し、
取得したい情報としてPromotionSummaryを選択すると、Java・PHP、Ruby on Railsでコードスニペットが表示されます。
それで表示されたJavaのコードです
java
1package com.amazon.advertising.api.sample; 2 3import java.util.HashMap; 4import java.util.Map; 5 6import javax.xml.parsers.DocumentBuilder; 7import javax.xml.parsers.DocumentBuilderFactory; 8 9import org.w3c.dom.Document; 10import org.w3c.dom.Node; 11 12/* 13 * This class shows how to make a simple authenticated call to the 14 * Amazon Product Advertising API. 15 * 16 * See the README.html that came with this sample for instructions on 17 * configuring and running the sample. 18 */ 19public class JavaCodeSnippet { 20 21 /* 22 * Your Access Key ID, as taken from the Your Account page. 23 */ 24 private static final String ACCESS_KEY_ID = ""; 25 26 /* 27 * Your Secret Key corresponding to the above ID, as taken from the 28 * Your Account page. 29 */ 30 private static final String SECRET_KEY = ""; 31 32 /* 33 * Use the end-point according to the region you are interested in. 34 */ 35 private static final String ENDPOINT = "webservices.amazon.com"; 36 37 public static void main(String[] args) { 38 39 /* 40 * Set up the signed requests helper. 41 */ 42 SignedRequestsHelper helper; 43 44 try { 45 helper = SignedRequestsHelper.getInstance(ENDPOINT, ACCESS_KEY_ID, SECRET_KEY); 46 } catch (Exception e) { 47 e.printStackTrace(); 48 return; 49 } 50 51 String requestUrl = null; 52 53 Map<String, String> params = new HashMap<String, String>(); 54 55 params.put("Service", "AWSECommerceService"); 56 params.put("Operation", "ItemSearch"); 57 params.put("AWSAccessKeyId", ""); 58 params.put("AssociateTag", ""); 59 params.put("SearchIndex", "All"); 60 params.put("ResponseGroup", "PromotionSummary"); 61 62 requestUrl = helper.sign(params); 63 64 System.out.println("Signed URL: \"" + requestUrl + "\""); 65 } 66}
試したこと
現状でAmazon Product Advertising APIを用いて、ASINから
商品名とタイトルは取得することができています。
以下コードの参考にしたサイト
Python
1from amazon.api import AmazonAPI 2 3AMAZON_ACCESS_KEY = "own_acess_key" 4AMAZON_SECRET_KEY = "own_secret_key" 5AMAZON_ASSOC_TAG = "own_assoc_tag" 6 7amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="JP") 8try: 9 product = amazon.lookup(ItemId="B01BEPNPF6") 10 print(product.title) #item name 11 print(product.price_and_currency) #price 12except Exception as e: 13 print (e)
補足情報(FW/ツールのバージョンなど)
Python 3.6.3
Mac OS High Sierra
回答2件
あなたの回答
tips
プレビュー