HTML
  Home arrow HTML arrow Page 3 - Hunting the Web Services at Amazon
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Hunting the Web Services at Amazon
By: Ahm Asaduzzaman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2003-03-17

    Table of Contents:
  • Hunting the Web Services at Amazon
  • Writing Your Application
  • Walkthrough Example
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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. 

    <html>
    <head>
    <basefont face="Verdana" size="2">
    </head>
    <body bgcolor="#F0F0F0">
    <table width="100%" cellspacing="1" cellpadding="5">
    <tr>
     <td bgcolor="Navy"><font color="white" size="-1"><b>Hunting at Amazon</b></font></td>
    </tr>
    </table>
    <?
    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>
    </select>
    <BR><BR> Enter a search term:<BR><input type="text" name="query">
    </form>
    <?
    }
    else
    {
    $ServiceType = $_POST['type'];
    // include class
    include("nusoap.php");
    // 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";
      break;
     case "artist":
      $mode = "music";
      $MyFunc = "ArtistSearchRequest";
      break;
     case "actor":
      $mode = "vhs";
      $MyFunc = "ActorSearchRequest";
      break;
     case "director":
      $mode = "vhs";
      $MyFunc = "DirectorSearchRequest";
      break;
     case "manufacturer":
      $mode = "electronics";
      $MyFunc = "ManufacturerSearchRequest";
      break;
    }
    //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
    //print_r($MyResult);
    $MyTotal = $MyResult['TotalResults'];
    $MyItems = $MyResult['Details'];
    // format and display the results
    ?>
    Search for <b><? echo $_POST['query']; ?></b> returned <? echo $MyTotal; ?> matches from Amazon.
    <p>
    <table width="100%" border="0" cellspacing="5" cellpadding="2">
    <?
    // parse the $MyItems[] array and extract the necessary information to display
    foreach ($MyItems as $i)
    {
    ?>
    <tr>
    <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'];
    }?>
    </font></td>
    </tr>
    <tr>
    <td align="left" valign="top"><font size="-1">List Price: <? echo $i['ListPrice']; ?> / Our Price: <? echo $i['OurPrice']; ?></font></td>
    </tr>
    <tr>
    <td align="left" valign="top"><font size="-1"><a href="<? echo $i['Url']; ?>">Read more at Amazon</a></font></td>
    </tr>
    <tr>
    <td colspan=2> </td>
    </tr>
    <?
    }
    ?>
    </table>
    <?
    }
    ?>
    </body>
    </html>

    More HTML Articles
    More By Ahm Asaduzzaman


     

    HTML ARTICLES

    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers
    - Downloading Long HTML Pages with ACP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek