CaRP Evolution Box
Web This Site

CaRP: Caching RSS Parser - Documentation


CaRP Interactive FAQ
Getting Started: Free Download | Purchase | Install
Reference: Functions | Plugins | Themes | Full Index
Etc.: Display Formatting | Example Code | Affiliates

Amazon.com Associates Example

Amazon.com associates, use this code to easy display best sellers based on whatever search terms you want The results are cached and refreshed every 12 hours, speeding the performance of your website. Once you've finished the main setup, adding custom best seller lists all over your website will be a snap!

This example was updated on 24 July 2009 to work with the most recent changes to Amazon's web services API. Earlier versions of the code will cease to work sometime in August when Amazon starts requiring all API requests to be digitally signed.
For another method of generating affiliates RSS feeds, check out Grouper Evolution. It includes plugins supporting Amazon.com, Shopping.com and All Posters' affiliate programs. [Affiliates RSS Example]

Here's how to use the code on your servr:

  1. Download the code and unzip it.
  2. Upload "Amazon2RSS-2.0-2009-06-01.xsl" to your webserver.
  3. Open "Amazon2RSS-2.0.php" in a text editor like Notepad (not a word processor like Word). If you're not in Windows, you may see funny characters at the beginning or end of every line. If so, either ignore them -- they're not important -- or get a text editor that can handle Windows or DOS style linebreaks.
  4. Make the following changes at the top of Amazon2RSS-2.0.php:
    • Change the part of the $xslt variable before "Amazon2RSS..." so that it points to the place where you uploaded Amazon2RSS-2.0-2009-06-01.xsl.
    • If you don't know your Access Key ID and Secret Key:
      1. Log into your Amazon affiliate account.
      2. Click "Product Advertising API" near the bottom of the menu on the left side of the page.
      3. Scroll down to the "Resources" section and click "Manage Your Account".
      4. In the "Access Identifiers" box, click "Click here".
      5. Your Access Key ID will be displayed automatically, but you'll need to click "Show" to display your Secret Access Key.
    • Enter your Amazon affiliate ID ("Associate Tag"). Access Key ID and Secret Key in the appropriate places -- enter them between the single quote marks like this:
      $AccessKeyId='k8af83jfa9fdaj39adf';
      $AssociateTag='moulc';
      $AmazonSecretKey='kas78fj4f9mfa9svdmsdfogasdfkasdfgf9';
    • If you wish to search a non-US Amazon site, change $county to the two letter code for the desired country.
  5. Upload Amazon2RSS.php and sha256.inc.php to the CaRP folder on your folder (put them in the same folder as carp.php).
  6. Find an Amazon.com logo you like and upload a copy of it to your website.
  7. Finally, copy the following code (which will be a template for adding Amazon links to your web pages) and save it on your computer, changing:
    • the URL of the image to point to the one uploaded to your site in the previous step.
    • the associates ID in the image link (where it says "tag=moulc") to your ID.
    • the path to where you uploaded Amazon2RSS-2.0.php on your server.
    <div style="width:200;height:420px;overflow:auto;margin:5px;padding:5px;background:#cccccc;">
    <span style="color:#003366;font-size:16pt;font-weight:bold;">Best sellers from</span><br>
    <a href="http://www.amazon.com/exec/obidos/redirect?tag=moulc&path=subst/home/home.html"><img src="http://www.yourwebsite.com/img/126X32-w-logo.gif" border="0"></a><br>
    <?php
    $q='web design';
    $MaxItems=5;
    $OneReview=1;
    $MaxReviewLength=250;
    $SearchIndex='Books';
    include '/path/to/Amazon2RSS-2.0.php';
    ?>
    </div>
    

You've completed the main setup. Now you can add Amazon links to any page by pasting a copy of the code saved in the last step above into your web page with the following changes as needed:

  • the styles of the div and span to look the way you want them to (If you don't want everything displayed in a scrolling box, remove the opening and closing div tags completely).
  • the value of $q to the search terms you wish to use.
  • the value of $MaxItems to the maximum number of items you wish to display.
  • the value of $OneReview to 0 if you wish to display as many customer reviews as Amazon gives you in response to the search query (generally 3, if that many are available). The default setting of $OneReview=1 displays one review.
  • the value of $MaxReviewLength to the maximum number of characters you want displayed from each review (0 = display the entire review).
  • the value of $SearchIndex to the appropriate value for whatever product category you wish to search, if not books. [As of this writing, the allowed values, some of which are not available in all countries, are as follows (refer to Amazon's documentation for details): Apparel, Baby, Beauty, Blended, Books, Classical, DigitalMusic, DVD, Electronics, ForeignBooks, GourmetFood, HealthPersonalCare, HomeGarden, Jewelry, Kitchen, Magazines, Merchants, Miscellaneous, Music, MusicalInstruments, MusicTracks, OfficeProducts, OutdoorLiving, PCHardware, PetSupplies, Photo, Restaurants, Software, SoftwareVideoGames, SportingGoods, Tools, Toys, VHS, Video, VideoGames, Wireless, WirelessAccessories.]

That's it! Depending on whether you are using the free or commercial version of CaRP, something like the examples to the right will appear on your web page.

TROUBLESHOOTING: If you follow the above steps and no items are displayed:

  1. Change the "if (0)" to "if (1)" in Amazon2RSS-2.0.php.
  2. Copy the URL that's displayed and save it somewhere.
  3. Change "if (1)" to "if (0)" and upload the file again to turn off display of the URL.
  4. Load the URL that was displayed in your web browser.

If what is displayed is in RSS format, then the XSL part of the system is working, and you need to figure out why CaRP isn't displaying it. More likely, it won't be in RSS format, but will be in Amazon's XML format. Hopefully there will be an error message in it somewhere telling you what went wrong. If not, things to check include:

  • Do your associate ID and access key ID appear in the URL? If not, fix those in Amazon2RSS-2.0.php.
  • Find the URL within the URL which points to your XSL file (Style=...). Copy the URL and paste it into your web browser. Does the XSL template get displayed? If not, fix the URL in Amazon2RSS-2.0.php.
Depending on whether you are using the free or commercial version of CaRP, the output will look similar to the following:

CaRP Evolution:

Best sellers from

Don't Make Me Think: A Common Sense Approach to Web Usability, 2nd Edition
by Steve Krug
Amazon Price: $24.99
Customer Review: Do I like the book?
Yes, an easy to read and simple book with easy to learn methods.
 
Head First HTML with CSS & XHTML
by Eric T Freeman, Elisabeth Freeman
Amazon Price: $26.39
Customer Review: Just how stupid do these people think we are?
I hate this book. Like the other one-star revie...
 
HTML, XHTML, and CSS, Sixth Edition
by Elizabeth Castro
Amazon Price: $23.09
Customer Review: Book was in great condition! They had extremely fast shipping and showed great care in packaging the...
 
Adobe Dreamweaver CS5 Classroom in a Book
by Adobe Creative Team
Amazon Price: $34.64
Customer Review: Of all the Classroom in a Book offerings for CS5, Dreamweaver is the book which has made a quantum l...
 
Learning Web Design: A Beginner's Guide to (X)HTML, StyleSheets, and Web Grap...
by Jennifer Niederst Robbins
Amazon Price: $29.69
Customer Review: Excellent Book.

The content of this book is very easy to understand.
 

CaRP LE:

Best sellers from

Don't Make Me Think: A Common Sense Approach to Web Usability, 2nd Edition
by Steve Krug

 
Head First HTML with CSS & XHTML
by Eric T Freeman, Elisabeth Freeman

 
HTML, XHTML, and CSS, Sixth Edition
by Elizabeth Castro

 
Adobe Dreamweaver CS5 Classroom in a Book
by Adobe Creative Team

 
Learning Web Design: A Beginner's Guide to (X)HTML, StyleSheets, and Web Grap...
by Jennifer Niederst Robbins