Amazon Associates API (data source) for CakePHP

Posted by Felix Geisendörfer, on Jul 31, 2008 - in PHP & CakePHP » DataSources, Models & Behaviors

Hey folks,

just wanted to let you know about a new addition to the debuggable scraps repository: An API for the Amazon Associates Web Service. Right now it's really just a simple wrapper to allow you to search their catalog since that was all I needed for now. But thanks to the almighty fork button on github you can easily change that ; ).

Using the API is as simple as:

php
  1. class AmazonController extends AppController{
  2.   var $uses = array();
  3.  
  4.   function index() {
  5.     // Only needed if no Model has been loaded so far
  6.     App::import('ConnectionManager');
  7.  
  8.     $amazon = ConnectionManager::getDataSource('amazon');
  9.     $response = $amazon->find('DVD', array('title' => 'The Devil and Daniel Johnston'));
  10.     debug($response);
  11.     exit;
  12.   }
  13. }

Documentation and code can be found here: Download the Amazon Associates API for CakePHP.

Hint: If you are looking for DVD covers you'll have to pass 'info' => 'Images' as a second query option.

Alright, hope that's useful to some of you out there : ),

-- Felix Geisendörfer aka the_undefined

Print this Post | Digg This | Stumble It | Delicious

4 Comments

rombeh on Aug 01, 2008:

interesting, as always. thanks for sharing, as always :)

Felix Geisendörfer on Aug 04, 2008:

PHP4 Hater: I'm not impressed with the quality of their implementation and solving my own problem took me 30 minutes without getting me into a dependency with a library component that claims to be a framework and is 20 megs to download ... I'm happy : )

Jason kritikos on Nov 04, 2008:

Hi there,

I have found a bug in this implementation, but i think it actually is a bug in cake's reverse function. More specifically, you invoke it at the end of your function as follows:
$r = Set::reverse(new Xml($r));

I have found out that when you do ItemLookup queries in amazon, although there are multiple Actor elements and multiple Format elements, the php array i end up is always populated with all values in the Actor and Format tags..On the other hand, i end up with a single Format element. If you want email me and i ll send you all the code so you can try it yourself..

thanks,

jason

Add a comment