/* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
/* Licensed under the Apache License, Version 2.0. */
/**
* Download the following artifacts and add to your projects classpath:
* o httpclient-4.5.5.jar
* o httpcore-4.4.9.jar
* o commons-logging-1.2.jar
* o json-20180130.jar
* Put your Secret Key in place of **********
* Make sure AWSV4Auth Class is available in same package
*/
package com.amazon.paapi.scratchpad;
import java.util.Map;
import java.util.TreeMap;
import java.nio.charset.StandardCharsets;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import com.amazon.paapi.scratchpad.AWSV4Auth;
public class GetItems {
private static final String HOST = "webservices.amazon.com";
private static final String URI_PATH = "/paapi5/getitems";
private static final String ACCESS_KEY = "thailyny95@gmail.com";
private static final String SECRET_KEY = "**********";
private static final String REGION = "us-east-1";
public static void main(String[] args) throws Exception {
String requestPayload =
"{"
+" \"ItemIds\": ["
+" \"B0DGQ31FT6\""
+" ],"
+" \"Resources\": ["
+" \"CustomerReviews.Count\","
+" \"CustomerReviews.StarRating\","
+" \"Images.Primary.Large\""
+" ],"
+" \"PartnerTag\": \"assfd134676-20\","
+" \"PartnerType\": \"Associates\","
+" \"Marketplace\": \"www.amazon.com\""
+"}";
TreeMap headers = new TreeMap();
headers.put("host", HOST);
headers.put("content-type", "application/json; charset=UTF-8");
headers.put("x-amz-target", "com.amazon.paapi5.v1.ProductAdvertisingAPIv1.GetItems");
headers.put("content-encoding", "amz-1.0");
AWSV4Auth awsv4Auth =
new AWSV4Auth.Builder(ACCESS_KEY, SECRET_KEY)
.path(URI_PATH)
.region(REGION)
.service("ProductAdvertisingAPI")
.httpMethodName("POST")
.headers(headers)
.payload(requestPayload)
.build();
HttpClient client = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost("https://" + HOST + URI_PATH);
httpPost.setEntity(new StringEntity(requestPayload));
Map header = awsv4Auth.getHeaders();
for (Map.Entry entrySet : header.entrySet()) {
httpPost.addHeader(entrySet.getKey(), entrySet.getValue());
}
HttpResponse response = client.execute(httpPost);
HttpEntity entity = response.getEntity();
String jsonResponse = EntityUtils.toString(entity, StandardCharsets.UTF_8);
int statusCode = response.getStatusLine().getStatusCode();
System.out.println(jsonResponse);
if(statusCode == 200) {
System.out.println("Successfully received response from Product Advertising API.");
System.out.println(jsonResponse);
} else {
JSONObject json = new JSONObject(jsonResponse);
if(json.has("Errors")) {
JSONArray errorArray = json.getJSONArray("Errors");
for(int i = 0; i < errorArray.length(); i++) {
JSONObject e = errorArray.getJSONObject(i);
System.out.println("Error Code: "+e.get("Code")+", Message: "+e.get("Message"));
}
} else {
System.out.println("Error Code: InternalFailure, Message: The request processing has failed because of an unknown error, exception or failure. Please retry again.");
}
}
}
}
Best 10 Online Learning Platforms In 2022 To Jumpstart Your Career
Still, also keep reading as you about to learn about 8 swish online knowledge platforms, If you have been cracking your head over the viability of MOOC courses and the online platforms to help you get the swish eschewal of them. Online knowledge platforms by IMHO Reviews Featured on News Networks 1.Skillshare 2.Coursera 3.Mindvalley 4.Udemy 5.Brilliant.org 6.Edx.org 7.Udacity 8.LinkedIn Learning (Ex Lynda) 9.MasterClass 10.Futurelearn 1. Skillshare Price Premium Membership (includes unlimited access to classes)-$ 32/ month or$ 168/ time Free Class (includes unlimited access to classes)-free Library classes Free Trial Yea (30- day free trial) Skillshare is one of the most popular online knowledge platforms. It has a massive collection of over classes that are divided into three orders Thrive (Lifestyle, Productivity), Figure ( Business Analytics, Freelance & Enterneuprenship, Leadership & Management, Marketing), and Produce (Animation, Film & Video, Graphic Design, Mu...
Comments
Post a Comment