Amazon Hacks Free Open Book

Amazon Hacks

Previous Section Next Section

Hack 77 Embed Product Details into a Web Page with PHP

figs/moderate.giffigs/hack77.gif

A simple way to display product data with existing PHP functions.

One great aspect of an open API is that other developers have probably already put together some tools to make your life easier. After all, why reinvent the wheel if someone else has already created what you need? These helper scripts are called wrappers because they wrap up some frequently used code into a few functions that you can call from another script. Daniel Filzhut, the author of the amazon_functions PHP wrapper, asks that people register if they earn quarterly associates fees greater than $50; but otherwise, it's free to try out or use for commercial purposes.

77.1 What You Need

To get started with this hack, you'll need to download the code from http://associatesshop.filzhut.de (choose "download" from the left-hand menu).

Unzip the package and open amazon_functions.php in the functions directory. Change the first line under Setup at the top of the file to include your developer's token:

define ("DEVTOKEN", "insert  developer token ");

77.2 The Code

The file with the helper functions is now ready to be included in any PHP script. This script has several functions that handle requesting information from Amazon and generating HTML based on the responses. Pick your favorite ASIN [Hack #1] and create a file called detail.php with the following code:

<?php

include('amazon_functions.php');

$Data=amazon_search_asin("0596004478","HEAVY");
$ProductInfoHTML=amazon_create_productinfo($Data);

echo $ProductInfoHTML;

php?>

Be sure to save both amazon_functions.php and detail.php to the same directory on your web server. Also, if you have a directory specified as an include_path in your php.ini configuration file, you can save amazon_functions.php there and it'll be available to all of your PHP scripts.

77.3 Running the Hack

Just browse to this file on your server to see it in action. The HTML written by this script includes an image of the product, a "buy from Amazon.com" button, the price, publisher, release date, and customer reviews. Not too shabby for just four lines of code! This code could be dropped into any PHP page so that the product details blend in with your site's design.

You'll find more than just the ASIN search method in the amazon_functions.php file. This file also has a simplified PHP interface to all of the AWS methods. Though you don't have complete control over the way product details are formatted, it's a great place to start if you'd like to integrate product data into an existing PHP-powered site.

    Previous Section Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Z]


         Main Menu
    Main Page
    Table of content
    Copyright
    Credits
    Foreword
    Preface
    Chapter 1. Browsing and Searching
    Chapter 2. Controlling Your Information
    Chapter 3. Participating in the Amazon Community
    Chapter 4. Selling Through Amazon
    Chapter 5. Associates Program
    Chapter 6. Amazon Web Services
    6.1 Hacks #76-100
    6.2 What Are Web Services?
    6.3 Why Expose an API?
    6.4 What You Need
    6.5 What You Can Do
    6.6 Making Requests
    6.7 The RESTful Way: XML/HTTP
    6.8 SOAP Web Services
    6.9 Working With Responses
    Hack 76 View XML Responses in a Browser
    Hack 77 Embed Product Details into a Web Page with PHP
    Hack 78 Program AWS with PHP
    Hack 79 Program AWS with Python
    Hack 80 Program AWS with Perl
    Hack 81 Loop Around the 10-Result Limit
    Hack 82 Program XML/HTTP with VBScript
    Hack 83 Transform AWS Results to HTML with XSLT
    Hack 84 Work Around Products Without Images
    Hack 85 Syndicate a List of Books with RSS
    Hack 86 Import Data Directly into Excel
    Hack 87 Program AWS with SOAP and VB.NET
    Hack 88 Program AWS with SOAP::Lite and Perl
    Hack 89 Program AWS with NuSOAP and PHP
    Hack 90 Create a Wireless Wish List
    Hack 91 Make Product Titles Shorter
    Hack 92 Encode Text for URLs
    Hack 93 Cache Amazon Images Locally
    Hack 94 Cache AWS Responses Locally
    Hack 95 Create an Amazon AIM Bot
    Hack 96 Compare International Sales
    Hack 97 Program AWS with Mozilla
    Hack 98 Search or Browse Amazon with Watson
    Hack 99 Add Cover Art to Your Digital Music Collection
    Hack 100 Using All Consuming's SOAP and REST Interfaces
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele