2017-05-16 60 views
0

我已經從亞馬遜便籤簿獲得代碼並獲得所需的包。 SignedRequestHelper類不在包中,我無法運行該程序。我試圖使用亞馬遜asin號碼獲得該物品的價格。亞馬遜廣告API:找不到SignedRequestHelper類

package com.amazon.advertising.api.sample; 

import java.util.HashMap; 
import java.util.Map; 

import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 

import org.w3c.dom.Document; 
import org.w3c.dom.Node; 

/* 
* This class shows how to make a simple authenticated call to the 
* Amazon Product Advertising API. 
* 
* See the README.html that came with this sample for instructions on 
* configuring and running the sample. 
*/ 
public class lookup { 

    /* 
    * Your AWS Access Key ID, as taken from the AWS Your Account page. 
    */ 
    private static final String AWS_ACCESS_KEY_ID = "XXXXXX"; 

    /* 
    * Your AWS Secret Key corresponding to the above ID, as taken from the AWS 
    * Your Account page. 
    */ 
    private static final String AWS_SECRET_KEY = "XXXXXXX"; 

    /* 
    * Use the end-point according to the region you are interested in. 
    */ 
    private static final String ENDPOINT = "webservices.amazon.com"; 


    public static void main(String[] args) { 

     /* 
     * Set up the signed requests helper. 
     */ 
     SignedRequestsHelper helper; 

     try { 
     } catch (Exception e) { 
      e.printStackTrace(); 
      return; 
     } 

     String requestUrl = null; 

     Map<String, String> params = new HashMap<String, String>(); 

     params.put("Service", "AWSECommerceService"); 
     params.put("Operation", "ItemLookup"); 
     params.put("AWSAccessKeyId", "XXXXXX"); 
     params.put("AssociateTag", "XXXXX"); 
     params.put("ItemId", "B01H57GXUQ"); 
     params.put("IdType", "ASIN"); 
     params.put("ResponseGroup", "Images,ItemAttributes,Offers"); 

     requestUrl = helper.sign(params); 

     System.out.println("Signed URL: \"" + requestUrl + "\""); 
    } 
} 

我將如何獲得signedrequestshelper方法或我將如何能夠更改代碼?

回答

0

SignedRequestHelper是從AWS這裏的代碼示例之一可用類:

http://docs.aws.amazon.com/AWSECommerceService/latest/DG/AuthJavaSampleSig2.html

您可以複製/粘貼代碼在你的項目,使其運行和工作。

+1

我也收到這三個錯誤,並想知道你是否能夠提供幫助。謝謝你的錯誤:未報告的異常UnsupportedEncodingException;必須被捕獲或聲明爲拋出 byte [] secretyKeyBytes = awsSecretKey.getBytes(UTF8_CHARSET); 錯誤:未報告的異常NoSuchAlgorithmException;必須被捕獲或聲明爲被拋出 mac = Mac.getInstance(HMAC_SHA256_ALGORITHM); 錯誤:未報告的異常InvalidKeyException;必須被捕獲或聲明爲被拋出 mac.init(secretKeySpec); – Max01