This is a quick snippet I put together for an academic project. To be able to write this, I had to go through several documentation resources, for what is essentially a single web service method call. I figured it would help if I shared my PHP code.
<?php
class ISBN {
function getMetadataFromIsbn($isbn) {
$awsAccessKeyID = 'YOUR_ACCESS_KEY_ID_HERE';
$awsSecretKey = 'YOUR_SECRET_KEY_HERE';
$awsAssociateTag = 'YOUR_ASSOCIATE_TAG_HERE';
$host = 'ecs.amazonaws.com';
$path = '/onca/xml';
$args = array(
'AssociateTag' => $awsAssociateTag,
'AWSAccessKeyId' => $awsAccessKeyID,
'IdType' => 'ISBN',
'ItemId' => $isbn,
'Operation' => 'ItemLookup',
'ResponseGroup' => 'Medium',
'SearchIndex' => 'Books',
'Service' => 'AWSECommerceService',
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version'=> '2009-01-06'
);
ksort($args);
$parts = array();
foreach(array_keys($args) as $key) {
$parts[] = $key . "=" . $args[$key];
}
$stringToSign = "GET\n" . $host . "\n" . $path . "\n" . implode("&", $parts);
$stringToSign = str_replace('+', '%20', $stringToSign);
$stringToSign = str_replace(':', '%3A', $stringToSign);
$stringToSign = str_replace(';', urlencode(';'), $stringToSign);
$signature = hash_hmac("sha256", $stringToSign, $awsSecretKey, TRUE);
$signature = base64_encode($signature);
$signature = str_replace('+', '%2B', $signature);
$signature = str_replace('=', '%3D', $signature);
$url = 'http://' . $host . $path . '?' . implode("&", $parts) . "&Signature=" . $signature;
$rawData = file_get_contents($url);
$metadata = simplexml_load_string($rawData);
if (isset($metadata->Items->Request->Errors)) {
return $metadata->Items->Request->Errors;
} else {
return $metadata->Items->Item;
}
}
}
?>
To Whom it May Concern:
Thanks so much for posting this; setting the IdType=ISBN was what I needed. My college’s library web application is sweet now because when users fill out a web form for a library item, they just have to provide the ISBN field, and all the rest of the fields are auto filled.
~Alicia Girvin
The College at Brockport (4/20/09)
Alicia Girvin — April 20, 2009 @ 12:46 pm
I know this a noob question but what exactly does this script return. I was hoping to return the book title from an isbn search but using this script I’m confused about how to return that.
Any help would be greatly appreciated, John
john — December 13, 2010 @ 8:44 am
Thanks for the info. It is sharp & clear.
Please, can you comment ashow to collect the data into a file e.g. Excel etc.
does it provide links to the pictureqvisual of the book/product ?
Any helpful comment will be appreciated.
Izzy Keren — September 11, 2011 @ 11:21 pm
Good. You can get the details using REST web services too:
http://www.javabeat.net/2012/05/implementing-restful-api-for-obtaining-the-book-details-for-an-isbn/
Krishna — May 8, 2012 @ 2:26 am
Please let me know how to read this information as an array.
ST — May 13, 2012 @ 10:12 pm