Using Amazon Web Services With PHP And SOAP (part 2) - Rolling The Stones (
Page 2 of 7 )
The first -
and the simplest - type of search available in AWS is the keyword search, exposed
via the KeywordSearchRequest() call. Here's a simple example of how it works:
<?php
// include class
include("nusoap.php");
// create a instance of the
SOAP client object
$soapclient = new
soapclient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl",
true);
//
set up an array containing input parameters to be
// passed to the remote procedure
$params
= array(
'keyword' => 'rolling%20stones',
'page' =>
1,
'mode' => 'books',
'tag' => 'melonfire-20',
'type' => 'lite',
'devtag' => 'YOUR-TOKEN-HERE'
);
// create
a proxy so that WSDL methods can be accessed directly
$proxy = $soapclient->getProxy();
//
invoke the method
$result = $proxy->KeywordSearchRequest($params);
// print
the results
print_r($result);
?>
This is functionally similar to the scripts you've seen thus far; the primary
difference lies in the call to a new function - KeywordSearchRequest() - and in
the different arguments passed to it. The "keyword" argument passed to the function
contains the words to be used as search keys in the specified Amazon catalog(s);
note that this search term must be URL-encoded before being passed to the function.
Here's sample output from the script above:
Array
(
[TotalResults] => 163
[Details] => Array
(
[0] => Array
(
[Url] =>
http://www.amazon.com/exec/obidos/redirect?tag=melonfire-20%26creative=Y
OUR-
TOKEN-HERE%26camp=2025%26link_code=sp1%26path=ASIN/1556523734
[Asin] => 1556523734
[ProductName] => Nankering
With the Rolling Stones
[Catalog] => Book
[Authors] => Array
(
[0]
=> James Phelge
)
[ReleaseDate] =>
April, 2000
[Manufacturer] => A Cappella Books
[ImageUrlSmall] =>
http://images.amazon.com/images/P/1556523734.01.THUMBZZZ.jpg
[ImageUrlMedium] =>
http://images.amazon.com/images/P/1556523734.01.MZZZZZZZ.jpg
[ImageUrlLarge] =>
http://images.amazon.com/images/P/1556523734.01.LZZZZZZZ.jpg
[ListPrice] => $16.95
[OurPrice] => $11.87
[UsedPrice] => $10.95
)
... snip ...
)
)
Next, let's see how this can be integrated into the sample store I've been building.