スキップしてメイン コンテンツに移動

投稿

ラベル(Amazon Product API)が付いた投稿を表示しています

Amazon Product Advertising API 5.0のJavaのサンプルコード

Amazon Product Advertising APIがjsonベースの5.0に移行することが発表されました。 Amazonが提供しているSDKを利用していない場合は、APIのリクエストのインターフェースがXMLからJSONに変わるので、コードの書き換えは結構面倒です。 Amazonの公式ページ でもSDKを使用しないバージョンのサンプルコードが公開されていますが、ApacheのHttpComponentsのライブラリとjsonのライブラリが依存関係に含まれていたので、とにかくAPIを動かしてみたい人向けに 標準のJDKだけで動作するサンプルコードを書きました。 (ただし実運用ではJacksonやGSONなど、何らかのjsonライブラリは必須です。) package com.dukesoftware.amazon; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; // Java8で動くように、あえてvarなどのJava8では使えないJava機能は未使用 // スクラッチパッドを使うと便利 // https://webservices.amazon.co.jp/paapi5/scratchpad/ public class AmazonProductAdvertisingApiV5 { public static void main(String[] args) { // request生成部分はJacksonやGSONなどのライブラリを使用するのが現実的 String jsonRequest = "{"

The Simplest Setup to Use Amazon Product API in Java

In this post, I will explain the simplest setup to use Amazon Product API in Java. I know Amazon provides soap interface and we can automatically create Soap code for accessing Amazon Product API. But sometimes, it is too much for light users. So I will show you the simplest way to use Amazon Product API using SignedRequestsHelper. Hope this post helps your application development ;) Preparation Create an AWS Account Get AWS Key, secret key and associate tag: I think you can create them from http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html Get SignedRequestsHelper: You can download from https://code.google.com/p/amazon-product-advertising-api-sample/source/browse/src/com/amazon/advertising/api/sample/SignedRequestsHelper.java Java Code Example Congratulation! After you finish above preparation, now you can request Amazon Product API!! The following code shows how to use SignedRequestsHelper. The key points of the examp