Home arrow HTML arrow Page 3 - Hunting the Web Services at Amazon

Hunting the Web Services at Amazon

Why is Amazon so popular? How can you use Amazon's web services? Ahm answers these questions and will help you develop websites using this service.

Author Info:
By: Ahm Asaduzzaman
Rating: 5 stars5 stars5 stars5 stars5 stars / 14
March 17, 2003
  1. · Hunting the Web Services at Amazon
  2. · Writing Your Application
  3. · Walkthrough Example
  4. · Conclusion

print this article

Hunting the Web Services at Amazon - Walkthrough Example
(Page 3 of 4 )

Now we will walk through an example, which demonstrates, how we can develop software with PHP that consume Web Services from Amazon.com. 

<basefont face="Verdana" size="2">
<body bgcolor="#F0F0F0">
<table width="100%" cellspacing="1" cellpadding="5">
 <td bgcolor="Navy"><font color="white" size="-1"><b>Hunting at Amazon</b></font></td>
if (!$_POST['query'])
Select a category:
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<select name="type" size="5">
 <option value="author">Author</option>
    <option value="artist">Artist</option>
    <option value="actor">Actor</option>
    <option selected value="director">Director</option>
    <option value="manufacturer">Manufacturer</option>
<BR><BR> Enter a search term:<BR><input type="text" name="query">
$ServiceType = $_POST['type'];
// include class
// create a instance of the SOAP client object
$soapclient = new soapclient("
http://soap.amazon.com/schemas2/AmazonWebServices.wsdl ", true);
// Create a proxy so that WSDL methods can be accessed directly. We can now invoke the remote method as method of the proxy class, and pass our parameters directly. The proxy objects will handle the details such as matching up parameters values to their names, assigning namespaces and types.
$proxy = $soapclient->getProxy();
// at this point you can use the following commented lines of code as check for error.
if ($err = $proxy->getError()) {
print "ERROR: $err";
} */
// set up an array containing input parameters to be
// passed to the remote procedure
// use a switch loop to define the search parameters for each type
switch ($ServiceType)
 case "author":
  $mode = "books";
  $MyFunc = "AuthorSearchRequest";
 case "artist":
  $mode = "music";
  $MyFunc = "ArtistSearchRequest";
 case "actor":
  $mode = "vhs";
  $MyFunc = "ActorSearchRequest";
 case "director":
  $mode = "vhs";
  $MyFunc = "DirectorSearchRequest";
 case "manufacturer":
  $mode = "electronics";
  $MyFunc = "ManufacturerSearchRequest";
//htmlentities - Convert all applicable characters to HTML entities
$params = array(
        $ServiceType         => htmlentities($_POST['query']),   
      'page'        => 1,
      'mode'        => $mode,
      'tag'         => 'Webservice-20',
      'type'        => 'lite',
      'devtag'      => 'D39A7USMOTRSNR' // the token I got from Amazon
// invoke the method
$MyResult = $proxy->$MyFunc($params);
/* if you are interested to see the contents of SOAP envelop  that has exchanged, uncomment the following two lines of codes.*/
//echo '<xmp>'.$proxy->request.'</xmp>';
//echo '<xmp>'.$proxy->response.'</xmp>';
// uncomment following lines to view the result
$MyTotal = $MyResult['TotalResults'];
$MyItems = $MyResult['Details'];
// format and display the results
Search for <b><? echo $_POST['query']; ?></b> returned <? echo $MyTotal; ?> matches from Amazon.
<table width="100%" border="0" cellspacing="5" cellpadding="2">
// parse the $MyItems[] array and extract the necessary information to display
foreach ($MyItems as $i)
<td align="center" valign="top" rowspan="3"><a href="<? echo $i['Url']; ?>"><img border="1" src=<? echo $i['ImageUrlSmall']; ?>></a></td>
<td><font size="-1"><b><? echo $i['ProductName']; ?></b> /
if (is_array($i['Authors']))
 //Join array elements with a string
 echo implode(", ", $i['Authors']);
else if (is_array($i['Artists'])) //Finds whether a variable is an array
 echo implode(", ", $i['Artists']);
else if ($i['Manufacturer'])
 echo $i['Manufacturer'];
<td align="left" valign="top"><font size="-1">List Price: <? echo $i['ListPrice']; ?> / Our Price: <? echo $i['OurPrice']; ?></font></td>
<td align="left" valign="top"><font size="-1"><a href="<? echo $i['Url']; ?>">Read more at Amazon</a></font></td>
<td colspan=2> </td>

blog comments powered by Disqus

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials