I've been doing a lot of digging around and have ended up with a huge headache and no success. I am trying to use the Zend Amazon Service (within my Codeigniter framework) to fetch information about a book using its ISBN. I initially tried it with Zend 1.12 but I kept getting an error about missing parameter AssociateTag. I am now trying with Zend 2.0 but still getting problems.
This is the code I am using within my controller:
set_include_path(get_include_path() . PATH_SEPARATOR . 'site/libraries');
require_once 'Zend2/Loader/StandardAutoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$amazon = new Zend_Service_Amazon('[apikey]', 'US', '[secretkey]');
$item = $amazon->itemLookup('B0000A432X');
I get the following error:
Fatal error: Class 'Zend_Loader_Autoloader' not found.
My questions are:
- How to load the correct autoloader?
- Where do I include the associate tag in the parameters? There is no mention of it in the outdated zend user guide
- Zend 2.0 doesn't even seem to have the amazon service files or even the /service folder. What does this mean?
i have use Amazon AWS S3 bucket along with Zend Framework. A simple example is photo upload to amazon AWS Bucket.In you
application/config/application.ini
fileLets say you want to upload an image to bucket, below is sample code of controller
Happy Coding !!!!
Note: The demo included with zendservice-amazon doesn't work as is. Requests must include your App ID, Secret Key, and Associate Tag which the demo script doesn't do by default. It took me a while to figure this out, without these, all queries throw an exception saying the HTTP response status was 400. Unfortunately the exception doesn't have the response body which says what parameters were missing.
Here is some code that will get you started with ZF2 and
ZendService\Amazon
.To start, let me outline the directory structure of where I will be putting files for this example:
The gist is I have created a directory called
testing
where we will place the ZF2 autoloader as well as the Amazon classes and their dependencies. Under testing is aZend
folder that contains the autoloader (inLoader
) and also aZendService
folder where theAmazon
service goes.First, we need to get a copy of the autoloader from ZF2. Part of the reason you were having trouble is because it looks like you are using the ZF1 autoloader which is incompatible with ZF2. To get the Autoloader from ZF2, you can download the latest ZF2 package and copy the
Loader
directory fromZendFramework-2.0.x/library/Zend/
into theZend
folder we created in thetesting
directory.Now that we have the autoloader files, let's grab the Amazon service files. I'll write a detailed answer on how to use Composer to get the latest package, but for now I'll explain how to get it manually. To get the full list of available ZF2 packages, load up the JSON file at http://packages.zendframework.com/packages.json In it find,
zendframework/zendservice-amazon
, determine the highest version available from the list, and grab the corresponding dist. EDIT As of 11th Jul 2013, this is the latest zendservice-amazon package.From the
library
directory inZendService_Amazon-2.0.2.zip
, copy the entireZendService
directory into thetesting
directory. You now have the ZF2 Amazon service files.Next, take care of the dependencies. From the ZF2 library, copy the directories,
Crypt
,Escaper
,Http
,I18n
,Json
,Stdlib
,Uri
, andValidator
into theZend
directory insidetesting
.You will also need the ZendRest package. Copy the
ZendRest
folder fromlibrary
from the ZendRest package totesting/ZendRest
.Now for some code. Create
test.php
inside thetesting
folder with the following contents:First, we
require_once
theStandardAutoloader
class from ZF2. Once the autoloader is registered, this is the only class you have to manually include.Next, we create a new autoloader and pass some options. This tells the autoloader where classes in the namespace
Zend
andZendService
are located. We tell the autoloader they live in the respective folders in our current directory. Changedirname(__FILE__)
to the correct path as needed. Thefallback_autoloader
option tells the autoloader to look for classes of any namespace or vendor in theinclude_path
.Calling
$autoloader->register();
then actually registers the autoloader we set up within PHP. Setting up the autoloader is now finished.The next 3 lines define some required parameters for the API.
The next 3 lines are straightforward, we now create a new instance of
ZendService\Amazon\Query
and pass our Amazon app ID and secret key. We then build the query by specifying to search in the BooksCategory
and set theKeywords
to be PHP. We also add the required AssociateTag. Finally, we execute the search.I
haven't yet usedcan't provide detailed instructions on using the class but the included demo script should get you started with sending basic queries to Amazon and processing the results.ZendService\Amazon
yet so IHope that helps.