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:
- Download the code and unzip it.
- Upload "Amazon2RSS-2.0-2011-08-01.xsl" to your webserver.
- 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.
- 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:
- Log into your Amazon affiliate account.
- Click "Product Advertising API" near the bottom of the menu on the left side of the page.
- Scroll down to the "Resources" section and click "Manage Your Account".
- In the "Access Identifiers" box, click "Click here".
- 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.
- Upload Amazon2RSS.php and sha256.inc.php to the CaRP folder on your folder (put them in the same folder as carp.php).
- Find an Amazon.com logo you like and upload a copy of it to your website.
- 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:
- Change the "if (0)" to "if (1)" in Amazon2RSS-2.0.php.
- Copy the URL that's displayed and save it somewhere.
- Change "if (1)" to "if (0)" and upload the file again to turn off display of the URL.
- 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.