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 30 March 2012 to work with the most recent changes to Amazon's web services API.
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-2011-08-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-2011-08-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

The $100 Startup: Reinvent the Way You Make a Living, Do What You Love, and C...
by Chris Guillebeau
Amazon Price: $13.80
In The $100 Startup, Chris Guillebeau shows you how to lead of life of adventure, mean...
 
The 4-Hour Workweek: Escape 9-5, Live Anywhere, and Join the New Rich (Expand...
by Timothy Ferriss
Amazon Price: $12.98
More than 100 pages of new, cutting-edge content.

Forget the old concept of retirement and t...
 
What Is HTML5?
by Brett McLaughlin
Amazon Price:

HTML5: Everyone?s using it, nobody knows what it is. I realize that sounds more like a line out o...


 
The Lean Startup: How Today's Entrepreneurs Use Continuous Innovation to Crea...
by Eric Ries
Amazon Price: $14.29

Most startups fail. But many of those failures are preventable.  The Lean Startup is a new app...


 
The Startup Owner's Manual: The Step-By-Step Guide for Building a Great Company
by Steve Blank, Bob Dorf
Amazon Price: $23.74
It's been called "the bible for startups" and "the best $40 investment a startup can make" (on sale ...
 

CaRP LE:

Best sellers from

The $100 Startup: Reinvent the Way You Make a Living, Do What You Love, and C...
by Chris Guillebeau

 
The 4-Hour Workweek: Escape 9-5, Live Anywhere, and Join the New Rich (Expand...
by Timothy Ferriss

 
What Is HTML5?
by Brett McLaughlin

 
The Lean Startup: How Today's Entrepreneurs Use Continuous Innovation to Crea...
by Eric Ries

 
The Startup Owner's Manual: The Step-By-Step Guide for Building a Great Company
by Steve Blank, Bob Dorf