comparison xml/amazonBookSearch.php @ 6:077b0a0a3e6d

remaining originals according to dependency walk
author Robert Boland <robert@markup.co.uk>
date Thu, 16 Feb 2017 22:29:02 +0000
parents
children ae1459564f66
comparison
equal deleted inserted replaced
5:55445b456ad0 6:077b0a0a3e6d
1 <?php
2
3 $Adefault=array(
4 'language' =>'en', //what language to render the page in
5 'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us
6 'page' =>1, //first page to show (we are counting from 1 not 0)
7 'operation' =>'ItemSearch', //what to do? //ItemSearch
8 'searchindex' =>'Books', //what product category for search?
9 'searchparameter' =>'Keywords', //what kind of search?
10 'searchparameterdata'=>'Machiavelli', //what to search for?
11 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
12 'show_url' =>false, //debug: show XML request url to be send to Amazon?
13 );
14
15 $Aassociates_id=array(
16 'uk' => 'bookwhack-21',
17 'us' => 'your02b-20',
18 'ca' => 'book009-20',
19 'de' => 'book04c-21',
20 'fr' => 'book07f-21',
21 );
22
23 $Aserver=array(
24 'ca' => array(
25 'ext' => 'ca' , //Canadian normal server
26 'nor' => 'http://www.amazon.ca' , //Canadian normal server
27 'xml' => 'http://xml.amazon.com' , //Canadian xml server
28 ),
29 'de' => array(
30 'ext' => 'de' , //German normal server
31 'nor' => 'http://www.amazon.de' , //German normal server
32 'xml' => 'http://xml-eu.amazon.com', //German xml server
33 ),
34 'fr' => array(
35 'ext' => 'fr' , //French normal server
36 'nor' => 'http://www.amazon.fr' , //French normal server
37 'xml' => 'http://xml-eu.amazon.com', //French xml server
38 ),
39 'jp' => array(
40 'ext' => 'jp' , //Japanese normal server, not co.jp!
41 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server
42 'xml' => 'http://xml.amazon.com' , //Japanese xml server
43 ),
44 'uk' => array(
45 'ext' => 'co.uk' , //UK normal server
46 'nor' => 'http://www.amazon.co.uk' , //UK normal server
47 'xml' => 'http://xml-eu.amazon.com', //UK xml server
48 ),
49 'us' => array(
50 'ext' => 'com' , //USA normal server
51 'nor' => 'http://www.amazon.com' , //USA normal server
52 'xml' => 'http://xml.amazon.com' , //USA xml server
53 ),
54 );
55
56 include "aws_signed_request.php";
57 $public_key ="AKIAJBXEHTNCU6LLFNIA";
58 $private_key="Dgyv7aR6uGe3OtY95Dj6hHpDS/UEtyboMWpJchYA";
59
60 //for all parameters see if the user has overruled it or use the default
61 foreach ($Adefault as $i=>$d) {
62 $$i=isset($_GET[$i])?$_GET[$i]:$d;
63 }
64 //this is the data that is used to form the request for AWS
65 //this is the part that is search specific
66
67 $parameters=array(
68 'Operation' =>$operation ,
69 //'Keywords' =>urlencode($search) ,
70 'SearchIndex' =>$searchindex , //Books for example.
71 "$searchparameter"=>stripslashes($searchparameterdata),
72 'ItemPage' =>$page , //which page?
73 'AssociateTag' =>$Aassociates_id[$locale],
74 'MerchantId' =>'All',
75 'Availability' =>'Available',
76 'Condition' =>'All',
77 'ResponseGroup' =>'Images,ItemAttributes' , //Small, Medium, Large or SellerListing
78 );
79
80 $ext=$Aserver[$locale]['ext'];
81 $file_data=$ext;
82 ksort($parameters);
83 foreach ($parameters as $i=>$d) {
84 $file_data.='&'.$i.'='.$d;
85 }
86
87 $url=aws_signed_request($ext,$parameters,$public_key,$private_key);
88 //echo $url;
89
90 $crl = curl_init();
91 $timeout = 5;
92 curl_setopt ($crl, CURLOPT_URL,$url);
93 curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
94 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
95 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
96 $ret = curl_exec($crl);
97 curl_close($crl);
98 echo $ret;