前提・実現したいこと
Amazon Product Advertising API Scratchpadを用いて、
商品のASINから商品画像を取得しようとしています。
Amazon API Scratchpad 公式サイト
ItemLookupのページでAssociateTagや商品のASINを入力し、
取得したい情報としてImageを選択すると、Java・PHP、Ruby on Railsで
コードスニペットが表示されます。
発生している問題・エラーメッセージ
開発はPythonで行なっているため、Javaで表示されたものをPythonに書き換える際に
Javaでは
params.put("ResponseGroup", "Images");
の部分をPythonではどのように書き換えたら良いかということと、
そもそも画像データはURLが取得されているのか画像ファイルをダウンロードしているのか
という点がわからず、困っています。
該当のソースコード
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 = "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 = "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.co.jp"; 36 37 public static void main(String[] args) { 38 39 /* 40 * Set up the signed requests helper. 41 */ 42 SignedRequestsHelper helper; //この部分がpythonではどこに当たるのか検討がつかない 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", "ItemLookup"); 57 params.put("AWSAccessKeyId", "ACCESS_KEY_ID"); //右側は自分のacesskey入力 58 params.put("AssociateTag", "AssociateTag"); //右側は自分のタグ名入力 59 params.put("ItemId", "B01BEPNPF6"); //ASINで商品検索 60 params.put("IdType", "ASIN"); 61 params.put("ResponseGroup", "Images"); 62 63 requestUrl = helper.sign(params); 64 65 System.out.println("Signed URL: \"" + requestUrl + "\""); 66 } 67}
試したこと
現状で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 :: Anaconda
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/08 10:57