Most recent edit on 2010-04-20 19:50:33 by MetalHead
Additions:
Building on this and wrapping some HTML around the results, maybe add some AJAX, you'd get something like this?. Keep in mind though that the PAS license limits you to 1 request per second -- you have to take care that this is not exceeded in your application yourself.
Deletions:
Building on this and wrapping some HTML around the results, maybe add some AJAX, you'd get something like this?. Keep in mind though that the PAS license limits you to 1 request per second -- you have to take care that this is not exceeded in your application yourself.
Edited on 2010-03-20 18:00:40 by MetalHead
Additions:
Building on this and wrapping some HTML around the results, maybe add some AJAX, you'd get something like this?. Keep in mind though that the PAS license limits you to 1 request per second -- you have to take care that this is not exceeded in your application yourself.
Edited on 2010-03-20 17:57:45 by MetalHead
Additions:
"<input type=\"hidden\" name=\"AssociateTag\" value=\"your associate tag\"/>" .
"<input type=\"hidden\" name=\"
SubscriptionId\" value=\"your subscription ID\"/>" .
Now we can do a simple echo addToCart
($item->
ASIN,
"uk");
inside the loop (change locale as appropriate).
Deletions:
default: $domain = $locale;
"<input type=\"hidden\" name=\"
AssociateTag\" value=\"amazonsimples-2\"/>" .
"<input type=\"hidden\" name=\"
SubscriptionId\" value=\"14ZHH69S2EX8TF2KJAR2\"/>" .
Now we can do a simple
echo addToCart($item->ASIN, "uk");
inside the loop (change locale as appropriate).
Edited on 2010-03-20 17:55:48 by MetalHead
Additions:
It would be nice to have a "add to cart" button as well. Unfortunately, there's no easy way to do this with the information we get back from Amazon. There is help available however at https://affiliate-program.amazon.com/gp/associates/help/t1/a10? -- we should wrap this in a function.
function addToCart($asin, $locale) {
switch($locale) {
case "us": $domain = "com"; break;
case "uk": $domain = "co.uk"; break;
case "de": $domain = "de"; break;
case "ca": $domain = "ca"; break;
case "fr": $domain = "fr"; break;
case "jp": $domain = "co.jp"; break;
default: $domain = $locale;
}
return("<form method=\"GET\" action=\"
http://www.amazon.?" . $domain . "/gp/aws/cart/add.html\">" .
"<input type=\"hidden\" name=\"
AssociateTag\" value=\"amazonsimples-2\"/>" .
"<input type=\"hidden\" name=\"
SubscriptionId\" value=\"14ZHH69S2EX8TF2KJAR2\"/>" .
"<input type=\"hidden\" name=\"ASIN.1\" value=\"". $asin ."\"/>" .
"<input type=\"hidden\" name=\"Quantity.1\" value=\"1\"/>" .
"<input type=\"submit\" name=\"add\" value=\"add to cart\">" .
"</form>");
Now we can do a simple
echo addToCart($item->ASIN, "uk");
inside the loop (change locale as appropriate).
Edited on 2010-03-20 17:49:25 by MetalHead
Additions:
Deletions:
Edited on 2010-03-20 17:47:49 by MetalHead
Additions:
Deletions:
Edited on 2010-03-20 17:43:51 by MetalHead
Additions:
Edited on 2010-03-20 17:41:38 by MetalHead
Additions:
Hmm, those formatted prices look a bit dodgy. We'll have to do something about the encoding. Fortunately, we can easily fix this in the HTML.
%%(html)
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8"/>
</head>
<body>
...
Better now. We can even do Japanese text.
$pas->set_locale("jp");
Amazonオリジナル マグカップ 黒 5.0
水野 貴明 俺流amazonの作り方―Amazon Webサービス最新活用テクニック 4.5 ¥ 2,730
- #12522;ボルテックダンボー・ミニ Amazon.co.jpボックスバージョン 4.5
Amazonベーシック 4.7GB 16倍速 DVD-R データ用 (100枚入 スピンドルケース) [フラストレーションフリーパッケージ(FFP)] 3.0 ¥ 1,635
松本 晃一 アマゾンの秘密──世界最大のネット書店はいかに日本で成功したか 4.0
- #21021;音ミク-Project DIVA2- 特典 ねんどろいどぷらす 「初音ミク Project DIVA」特典Ver チャーム(仮)付き ¥ 4,698
- #12304;Amazon.co.jp限定】(お徳用ボックス) ラーメンバラエティアソートセット(海鮮中華そば・とりがら醤油・みそ・北海道みそ・北海道味噌・北海道塩 各2個) 4.5 ¥ 1,680
Amazonオリジナル マグカップ 白 4.5
Amazonベーシック 700MB 52倍速 CD-R (50枚入 スピンドルケース) [フラストレーションフリーパッケージ(FFP)] 3.5 ¥ 849
並河祐貴 クラウド Amazon EC2/S3のすべて~実践者から学ぶ設計/構築/運用ノウハウ~ (ITpro BOOKs) 3.0 ¥ 2,940
Edited on 2010-03-20 17:35:53 by MetalHead
Additions:
Linking back to Amazon
Just a list of results is not terribly useful. Let's link back to the Amazon detail pages.
This also works for other Amazon sites, just change the locale.
$pas->set_locale("uk");
Bruce Parry Amazon. An Extraordinary Journey Down The Greatest River On Earth 5.0 £14.49
Vax V-124A Dual V Upright Carpet Washer 4.5 £249.99
AmazonBasics 3M Quad-Shielded High Speed HDMI Cable [Amazon Frustration-Free Packaging] 4.5 £12.99
Amazon [DVD] [2008] 4.5 £8.47
Brad Schepp Amazon Top Seller Secrets: Inside Tips From Amazon's Most Successful Sellers 5.0 £11.21
Dyson DC14 Origin Upright Vacuum Cleaner for Carpeted Homes 5.0 £178.70
AmazonBasics 2M Dual-Shielded High Speed HDMI Cable [Amazon Frustration-Free Packaging] 4.5 £4.99
Medical Carrycase 4.5 £5.25
Andes To Amazon [DVD] 4.5 £12.95
Matthew Mohlke & Martin Strel The Man who Swam the Amazon: 3,274 Miles on the World's Deadliest River 4.0 £4.76
Edited on 2010-03-20 17:30:16 by MetalHead
Additions:
Displaying the data
Getting more data
The service only returns results for the first 10 items. We can get more by setting ItemPage in the request.
$res = $pas->item_search("amazon", array('ResponseGroup' => 'Large', 'ItemPage' => 2));
echo $res->body->Items->
TotalResults . " results on " . $res->body->Items->
TotalPages . " pages of results<br/>";
20802817 results on 2080282 pages of results Etienne Aigner Tuscon Bucket Hobo,Garden Floral,one size $64.99
Etienne Aigner Tucson Tote,Garden Floral,one size $69.99
Robert Spector Amazon.com: Get Big Fast 3.5 $12.48
Seventh Generation Chlorine Free Baby Diapers, Stage 2 (12-18 Lbs.), Case of 160 Diapers [Amazon Frustration-Free Packaging] 4.0 $39.99
Nine West Central Time Small Cross Body,Black/Black/Black,one size $52.63
crocs Women's Malindi Flat Slingback,Black,7 M 4.5 $28.02
Rebecca Saunders Big Shots, Business the Amazon.com Way: Secrets of the Worlds Most Astonishing Web Business (2nd Edition) 2.5 $19.46
Steve Madden Men's S089 Aviator Sunglasses,Gun-Blue Frame/Gradient Smoke Lens,one size $40.00
Amazon Kindle DX Leather Cover (Fits 9.7" Display, Latest Generation Kindle DX) 3.5 $49.99
Roger Harris The Amazon, 3rd: The Bradt Travel Guide 4.5 $17.15
Deletions:
Doing something with the result
Edited on 2010-03-20 17:24:39 by MetalHead
Additions:
That's better. We can dive a bit deeper and get some more information. Let's change the ResponseGroup to Large as well to get additional information back from the service.
Deletions:
That's better. We can dive a bit deeper and get some more information. Let's change the ##ResponseGroup## to Large as well to get additional information back from the service.
Edited on 2010-03-20 17:24:21 by MetalHead
Additions:
That's better. We can dive a bit deeper and get some more information. Let's change the ##ResponseGroup## to Large as well to get additional information back from the service.
Deletions:
That's better. We can dive a bit deeper and get some more information. Let's change the ResponseGroup to Large as well to get additional information back from the service.
Edited on 2010-03-20 17:23:58 by MetalHead
Additions:
It looks like we're not getting the same information back for all of the items. Unfortunately, there's nothing we can do about that. Have a look at the response from the service to see if there's another attribute that you could use if one is unavailable. For example, apart from Author, there's also Creator and Manufacturer.
Edited on 2010-03-20 17:21:49 by MetalHead
Additions:
var_dump($pas->item_search("amazon"));
$res = $pas->item_search("amazon");
Nine West Central Time Medium E/W Satchel,Black/Black/Black,one size
The Lost City of Z: A Tale of Deadly Obsession in the Amazon (Vintage Departures)
Etienne Aigner Tucson Tote,Patchwork,one size
Sell on Amazon: A Guide to Amazon's Marketplace, Seller Central, and Fulfillment by Amazon Programs
Kindle Wireless Reading Device (6" Display, Global Wireless, Latest Generation)
Bearpaw Women's M410 10" Boot,Black,9 M US
KATHY Van Zeeland Drop Off Service A Line Shopper,Frosting,one size
Amazon Kindle Black Leather Cover w/ strap (Fits 6" Display, Latest Generation Kindle)
Amazon Top Seller Secrets: Insider Tips from Amazon's Most Successful Sellers
Etienne Aigner Tuscon Bucket Hobo,Garden Floral,one size
That's better. We can dive a bit deeper and get some more information. Let's change the ResponseGroup to Large as well to get additional information back from the service.
$res = $pas->item_search("amazon", array('ResponseGroup' => 'Large'));
Nine West Central Time Medium E/W Satchel,Black/Black/Black,one size $89.00
David Grann The Lost City of Z: A Tale of Deadly Obsession in the Amazon (Vintage Departures) 4.0 $9.32
Etienne Aigner Tucson Tote,Patchwork,one size $79.99
Steve Weber Sell on Amazon: A Guide to Amazon's Marketplace, Seller Central, and Fulfillment by Amazon Programs 4.5 $17.05
Kindle Wireless Reading Device (6" Display, Global Wireless, Latest Generation) 4.0 $259.00
Bearpaw Women's M410 10" Boot,Black,9 M US 4.0 $54.03
KATHY Van Zeeland Drop Off Service A Line Shopper,Frosting,one size $99.00
Amazon Kindle Black Leather Cover w/ strap (Fits 6" Display, Latest Generation Kindle) 4.0 $34.99
Brad Schepp Amazon Top Seller Secrets: Insider Tips from Amazon's Most Successful Sellers 4.0 $16.47
Etienne Aigner Tuscon Bucket Hobo,Garden Floral,one size $64.99
Deletions:
var_dump($pas->item_search("foobar"));
$res = $pas->item_search("foobar");
Your Fiend, My Friend
Your Fiend My Friend
Test Title Foobar
Personal Name Gift - "FOO-BAR" Set of 4 Mini-Mousepad Coasters (black design)
Moonshine
Natural
18 Years
Queen Of Fools
Catch 22
My Friend
That's better. We can dive a bit deeper and get some more information.
Edited on 2010-03-20 17:16:09 by MetalHead
Additions:
foreach($res->body->Items->Item as $item) {
Deletions:
Edited on 2010-03-20 17:12:19 by MetalHead
Additions:
First steps
Doing something with the result
While the documentation for the CloudFusion AmazonPAS? class is very good and the documentation of the ResponseGroup part of the Amazon API? is very extensive as well, it can be somewhat difficult to figure out where the things that you want are. I found it easiest to simply look at the XML of the response -- var_dump is your friend.
So, first to display the titles that the search gaves us back.
$res =
$pas->
item_search("foobar");
if($res->
isOK()) {
foreach($res->
body->
Items->
Item as $item) {
echo $item->
ItemAttributes->
Title .
"<br/>";
}
}
Your Fiend, My Friend
Your Fiend My Friend
Test Title Foobar
Personal Name Gift - "FOO-BAR" Set of 4 Mini-Mousepad Coasters (black design)
Moonshine
Natural
18 Years
Queen Of Fools
Catch 22
My Friend
Deletions:
First steps
Oldest known version of this page was edited on 2010-03-20 17:04:07 by MetalHead []
Page view:
Using AWS for Amazon Search
Amazon's
Product Advertising API? (formerly ECS) provides access to the information you can find on the website. Integrating it in your own application is easy, thanks to libraries that wrap the interface and do all the heavy lifting for you. I've had a look at creating an Amazon search engine with
CloudFusion?.
First steps
Setup is just about as simple as it gets. Download the latest release, unpack it into a directory on your webserver, edit the short configuration file and rename it to
config.inc.php. Now we just need a simple file to test our setup.
<?php
require_once 'cloudfusion/cloudfusion.class.php';
$pas =
new AmazonPAS
();
var_dump($pas->
item_search("foobar"));
?>
And that's it! The result is nothing you could put on your webpage, but at least we know that it works now.