Mercurial > hg > ywww
view xml/amazonBookSearch.php @ 43:dbc006408d2b
ASSUMES we have SetEnv PHP_VALUE "include_path =.:/var/test/private:/var/test/ywww:/usr/share/php" in apache2/.../test.conf
use dl(...) for debug logging, defined in dlog.php
use doAmazonRequest in amazonBookSearch
use ../private/web.php (q.v., not in mercurial) for Aserver and Aassociates
Started by updating from 40:c24ae74bf6d5, i.e. just before the bug on the main line
author | Charlie Root |
---|---|
date | Sat, 05 Jan 2019 18:00:10 -0500 |
parents | b1bbf44c701b |
children | 38d209611508 |
line wrap: on
line source
<?php include_once "dlog.php"; include_once "doAmazonRequest.inc"; $Adefault=array( 'language' =>'en', //what language to render the page in 'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us 'page' =>1, //first page to show (we are counting from 1 not 0) 'operation' =>'ItemSearch', //what to do? //ItemSearch 'searchindex' =>'Books', //what product category for search? 'searchparameter' =>'Keywords', //what kind of search? 'searchparameterdata'=>'Machiavelli', //what to search for? //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true' 'show_url' =>false, //debug: show XML request url to be send to Amazon? ); //for all parameters see if the user has overruled it or use the default foreach ($Adefault as $i=>$d) { $$i=isset($_GET[$i])?$_GET[$i]:$d; } //this is the data that is used to form the request for AWS //this is the part that is search specific $parameters=array( 'Operation' =>$operation , //'Keywords' =>urlencode($search) , 'SearchIndex' =>$searchindex , //Books for example. "$searchparameter"=>stripslashes($searchparameterdata), 'ItemPage' =>$page , //which page? 'AssociateTag' =>$Aassociates_id[$locale], 'MerchantId' =>'All', 'Availability' =>'Available', 'Condition' =>'All', 'ResponseGroup' =>'Images,ItemAttributes' , //Small, Medium, Large or SellerListing ); try { $ret=doAmazonRequest($Aserver[$locale]['ext'],$parameters,3,'s',False); } catch (Exception $e) { if ($e->getMessage()=='AWS.ECommerceService.NoExactMatches') { // Seems to be an 'OK' thing... $ret='<?xml version="1.0" ?><ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"><OperationRequest><RequestId>0e41c74c-eeff-4f24-a761-9537cfebea21</RequestId></OperationRequest><Items><Request><IsValid>True</IsValid></Request><TotalResults>0</TotalResults><TotalPages>0</TotalPages></Items></ItemSearchResponse>'; } else { $ret='<?xml version="1.0" ?><ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"><OperationRequest><RequestId>0e41c74c-eeff-4f24-a761-9537cfebea21</RequestId></OperationRequest><Items><Request><IsValid>True</IsValid><Errors><Error><Code>'.$code.'</Code><Message>[lost]</Message></Error></Errors></Request><TotalResults>0</TotalResults><TotalPages>0</TotalPages></Items></ItemSearchResponse>'; } } echo $ret;