亚马逊商品广告API已与Java的请求 [英] Amazon Product Advertising API signed request with Java

查看:178
本文介绍了亚马逊商品广告API已与Java的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多时间修修补补和读取整个互​​联网几次后,我只是无法弄清楚如何注册与产品广告API的使用要求。

after many hours of tinkering and reading the whole internet several times I just can't figure out how to sign requests for use with the Product Advertising API.

到目前为止,我设法生成从提供的WSDL文件的客户端。我用了一个教程亚马逊这一点。你可以在这里找到它:

So far I managed to generate a client from the provided WSDL file. I used a tutorial by Amazon for this. You can find it here:

<一个href="http://docs.amazonwebservices.com/AWSECommerceService/latest/GSG/index.html?YourDevelopmentEnvironment.html">Tutorial生成Web服务客户端

到目前为止,没有任何问题。为了测试客户端,我写了一小块code。在code是为了简单地得到关于产品的一些信息。该产品是由它的ASIN指定。

So far no problems. To test the client I wrote a small piece of code. The code is intended to simply get some information about a product. The product is specified by its ASIN.

在code:

package client;

import com.ECS.client.jax.AWSECommerceService;
import com.ECS.client.jax.AWSECommerceServicePortType;
import com.ECS.client.jax.ItemLookup;
import com.ECS.client.jax.ItemLookupResponse;
import com.ECS.client.jax.ItemLookupRequest;

public class Client {

  public static void main(String[] args) {
    System.out.println("API Test startet");

    AWSECommerceService service = new AWSECommerceService();
    AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

    ItemLookupRequest itemLookup = new ItemLookupRequest();
    itemLookup.setIdType("ASIN");
    itemLookup.getItemId().add("B000RE216U");

    ItemLookup lookup = new ItemLookup();
    lookup.setAWSAccessKeyId("<mykeyishere>");
    lookup.getRequest().add(itemLookup);

    ItemLookupResponse response = port.itemLookup(lookup);

    String r = response.toString();
    System.out.println("response: " + r);

    System.out.println("API Test stopped");
  }
}

正如你可以看到有没有参与,我请求签名。我已经经历了很多使用的类的签名请求的工作我的方式,并没有发现任何的方法。

As you can see there is no part where I sign the request. I have worked my way through a lot of the classes used and found no methods for signing the request.

那么,如何签署的要求?

So, how to sign a request?

其实,我发现了一些东西的文档中:请求验证

I actually found something in the documentation: request authentication

但他们不使用自己的API。提出的解决方案都或多或少仅供手动使用。所以,我看着在客户端类理清如果我能得到请求的URL,并把所有需要签名的请求在自己的部分。但目前还没有这样的方法。

But they don't use their own API. The proposed solutions are more or less for manual use only. So I looked in the client classes to sort out if I could get the request URL and put all the parts needed for request signing in myself. But there are no such methods.

我希望有人能指出我在做什么错。

I hope someone can point out what I am doing wrong.

这是我做过什么来解决这个问题。全部归功于乔恩和亚马逊论坛的家伙。

This is what I did to solve the problem. All the credit goes to Jon and the guys of the Amazon forums.

在我概述我做什么,这里是一个链接到帮我解决问题的帖子:的论坛帖子在亚马逊论坛的。

Before I outline what I did, here is a link to the post which helped me to solve the problem: Forum Post on Amazon forums.

我下载的是在后链接的awshandlerresolver.java。比我修改了自己的code,所以它看起来是这样的:

I downloaded the awshandlerresolver.java which is linked in the post. Than I modified my own code so it looks like this:

package client;

import com.ECS.client.jax.AWSECommerceService;
import com.ECS.client.jax.AWSECommerceServicePortType;
import com.ECS.client.jax.ItemLookup;
import com.ECS.client.jax.ItemLookupResponse;
import com.ECS.client.jax.ItemLookupRequest;

public class Client {

  public static void main(String[] args) {
    System.out.println("API Test startet");

    AWSECommerceService service = new AWSECommerceService();
    service.setHandlerResolver(new AwsHandlerResolver("<Secret Key>"));  // important
    AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

    ItemLookupRequest itemLookup = new ItemLookupRequest();
    itemLookup.setIdType("ASIN");
    itemLookup.getItemId().add("B000RE216U");

    ItemLookup lookup = new ItemLookup();
    lookup.setAWSAccessKeyId("<Access Key>"); // important
    lookup.getRequest().add(itemLookup);

    ItemLookupResponse response = port.itemLookup(lookup);

    String r = response.toString();
    System.out.println("response: " + r);   
    System.out.println("API Test stopped");
  }
}

在端的的println或多或少无用。但是,它的工作原理。我还用在WSDL乔恩链接到生成新的web服务客户端。我只是改变了网址在我张贴在我的问题的教程。

The println on the end are more or less useless. But it works. I also used the WSDL Jon linked to generate a new webservice client. I just changed the URLs in the tutorial I posted in my question.

推荐答案

试试这个AFER您创建服务

Try this afer you create the service

service.setHandlerResolver(new AwsHandlerResolver(my_AWS_SECRET_KEY));

您将需要<一个href="http://developer.amazonwebservices.com/connect/servlet/JiveServlet/download/53-35999-143146-2680/awshandlerresolver.java">this类这个的jar文件添加为引用您的项目作为AwsHandlerResolver使用的Base64编码。

You'll need this class and this jar file to add as a reference to your project as AwsHandlerResolver uses Base64 encoding.

您需要将AwsHandlerResolver文件重命名为类的名称作为文件名是小写。

You'll need to rename the AwsHandlerResolver file to the name of the class as the file name is all lower case.

我认为,code你有剩下的就是好的。

I think the rest of the code you have is fine.

该WSDL是<一个href="http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl">http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

这篇关于亚马逊商品广告API已与Java的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆