forked from chopin2256/Amazon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
56 lines (44 loc) · 1.43 KB
/
index.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
<?php
//Require the class file
require_once('Amazon.php');
//Run Amazon
runAmazon();
function runAmazon() {
$amazon = new Amazon(); //Instantiate Amazon object
$kw = "product title"; //Set keyword
$cnt = 5; //Set amazon max results, up to 10
//Set config options
$amazon->config()
->API_KEY('Your API')
->SECRET_KEY('Your Secret Key')
->associate_tag('associatetag-20')
->locale('com')
->maxResults($cnt);
//Search for keyword
$amazon->search($kw);
//Loop through array in for loop to save your Amazon results
for ($i = 0; $i < $cnt; $i++) {
$result .= amazonLayout($i, $amazon);
}
//Clear amazon object
$amazon->clear();
//Set and return results, in this case, 5 product titles
echo $result;
}
function amazonLayout($i, Amazon $amazon) {
//Get your amazon attributes here
$image = $amazon->get()->image("LargeImage");
$priceLowNew = $amazon->get()->price("lowestNew");
$priceUsed = $amazon->get()->price("lowestUsed");
$offersNew = $amazon->get()->numOffers("TotalNew");
$offersUsed = $amazon->get()->numOffers("TotalUsed");
$url = $amazon->get()->url();
$title = $amazon->get()->title();
$desc = $amazon->get()->description();
//Your custom code and formatting here
$newTitle = "<div>$title[$i]</div>";
$newUrl = "<div>$url[$i]</div>";
//..etc
return $newTitle;
}
?>