-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazon-asin.php
91 lines (89 loc) · 2.96 KB
/
amazon-asin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
include('amazon_api.php');
/* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
/* Licensed under the Apache License, Version 2.0. */
$ASIN = 'B084DWH53T'; //enter asin of product
$serviceName = "ProductAdvertisingAPI";
$region = "eu-west-1";
$accessKey = "Enter your access key"; // Enter your access key
$secretKey = "Enter your secret key"; //Enter your secret key
$AssociateTag = "Enter your associate tag"; //Enter your associate tag
$payload = "{"
. " \"ItemIds\": ["
. " \"$ASIN\""
. " ],"
. " \"Resources\": ["
. " \"Images.Primary.Large\","
. " \"ItemInfo.Features\","
. " \"ItemInfo.Title\","
. " \"Offers.Listings.Price\","
." \"Offers.Listings.SavingBasis\""
. " ],"
. " \"PartnerTag\": \"$AssociateTag\","
. " \"PartnerType\": \"Associates\","
. " \"Marketplace\": \"www.amazon.in\""
. "}";
$host = "webservices.amazon.in";
$uriPath = "/paapi5/getitems";
$awsv4 = new AwsV4($accessKey, $secretKey);
$awsv4->setRegionName($region);
$awsv4->setServiceName($serviceName);
$awsv4->setPath($uriPath);
$awsv4->setPayload($payload);
$awsv4->setRequestMethod("POST");
$awsv4->addHeader('content-encoding', 'amz-1.0');
$awsv4->addHeader('content-type', 'application/json; charset=utf-8');
$awsv4->addHeader('host', $host);
$awsv4->addHeader('x-amz-target', 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.GetItems');
$headers = $awsv4->getHeaders();
$headerString = "";
foreach ($headers as $key => $value) {
$headerString .= $key . ': ' . $value . "\r\n";
}
$params = array(
'http' => array(
'header' => $headerString,
'method' => 'POST',
'content' => $payload,
),
);
$stream = stream_context_create($params);
$fp = @fopen('https://' . $host . $uriPath, 'rb', false, $stream);
if (!$fp) {
throw new Exception("Exception Occured");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Exception Occured");
}
$details = json_decode($response, true);
$product = $details['ItemsResult']['Items']['0'];
if (isset($details['ItemsResult']['Items']['0'])) {
$asin = $product['ASIN'];
$productUrl = $product['DetailPageURL'];
}
if (isset($product['ItemInfo'])) {
$title = $product['ItemInfo']['Title']['DisplayValue'];
$features = $product['ItemInfo']['Features']['DisplayValues'];
foreach ($features as $feature) {
$feature .= $feature;
}
}
if (isset($product['Images'])) {
$image = $product['Images']['Primary']['Large']['URL'];
}
if (isset($product['Offers'])) {
$Sellprice = $product['Offers']['Listings']['0']['Price']['Amount'];
if(!$Sellprice){
echo "Sell Price is not present.";
}
}else{
$Sellprice = 0;
}
if(isset($product['Offers']['Listings']['0']['SavingBasis'])){
$Maxprice = $MaxPrice =$product['Offers']['Listings']['0']['SavingBasis']['Amount'];
}else{
$MaxPrice = 0;
}
echo $response;
?>