· 5 years ago · Nov 26, 2019, 10:46 AM
1<?php
2
3/**
4 * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License").
7 * You may not use this file except in compliance with the License.
8 * A copy of the License is located at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * or in the "license" file accompanying this file. This file is distributed
13 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * express or implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 */
17
18require_once("AwsV4.php");
19
20$searchItemRequest = new SearchItemsRequest ();
21$searchItemRequest->PartnerType = "Associates";
22// Put your Partner tag (Store/Tracking id) in place of Partner tag
23$searchItemRequest->PartnerTag = "MIO-TAG-AMAZON";
24$searchItemRequest->Keywords = "Harry";
25$searchItemRequest->SearchIndex = "All";
26$searchItemRequest->Resources = ["Images.Primary.Small","ItemInfo.Title","Offers.Listings.Price"];
27$host = "webservices.amazon.com";
28$path = "/paapi5/searchitems";
29$payload = json_encode ($searchItemRequest);
30//Put your Access Key in place of <ACCESS_KEY> and Secret Key in place of <SECRET_KEY> in double quotes
31$awsv4 = new AwsV4 ("MIO_ACCESSO", "CHIAVE_PRIVATA");
32$awsv4->setRegionName("us-east-1");
33$awsv4->setServiceName("ProductAdvertisingAPI");
34$awsv4->setPath ($path);
35$awsv4->setPayload ($payload);
36$awsv4->setRequestMethod ("POST");
37$awsv4->addHeader ('content-encoding', 'amz-1.0');
38$awsv4->addHeader ('content-type', 'application/json; charset=utf-8');
39$awsv4->addHeader ('host', $host);
40$awsv4->addHeader ('x-amz-target', 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems');
41$headers = $awsv4->getHeaders ();
42$headerString = "";
43foreach ( $headers as $key => $value ) {
44 $headerString .= $key . ': ' . $value . "\r\n";
45}
46$params = array (
47 'http' => array (
48 'header' => $headerString,
49 'method' => 'POST',
50 'content' => $payload
51 )
52 );
53$stream = stream_context_create ( $params );
54
55$fp = @fopen ( 'https://'.$host.$path, 'rb', false, $stream );
56
57if (! $fp) {
58 throw new Exception ( "Exception Occured" );
59}
60$response = @stream_get_contents ( $fp );
61if ($response === false) {
62 throw new Exception ( "Exception Occured" );
63}
64echo $response;
65
66class SearchItemsRequest {
67 public $PartnerType;
68 public $PartnerTag;
69 public $Keywords;
70 public $SearchIndex;
71 public $Resources;
72}
73?>