How do I get a book graphic and description from the Amazon Book API?

一笑奈何 提交于 2019-11-28 16:49:55

问题


This URL sends an ISBN number to Amazon and gets back a small bit of XML including author, title, and publisher.

However, I also want to get small, medium and large graphic and book descriptions of the title.

Problem: I can find no REST URL examples/documention that work, either at Google or when logged into my "AWS Account" at Amazon Associates.

I find a lot of examples from 2003-2005 but they are all out-of-date and give errors, it seems that Amazon's cloud web services have obfuscated their simple REST API documentation for their books.

Can anyone point me to some documentation on how I can get detailed information about books at Amazon via REST/XML?

Here's what I have tried so far.


回答1:


So, allow me to answer my own question, from another question here I found this useful PDF and the following URL gets images for instance, see "ResponseGroup"




回答2:


ResponseGroup is the key, and if you specify more than one (comma separated) the results are stitched together

That is, "&ResponseGroup=Images,Small" returns the minimal details and images about products




回答3:


I have build some functions to grab amazon xml using php and curl using simple functions just like this:

    <?php
function Get_Amazon_XML($tag, $api, $secretkey, $region, $department, $query)
{
$time = time() + 10000;
$method = 'GET';
$host = 'webservices.amazon.'.$region;
$uri = '/onca/xml';
$slug["Service"] = "AWSECommerceService";
$slug["Operation"] = "ItemSearch";
$slug["SubscriptionId"] = $api;
$slug["AssociateTag"] = $tag;
$slug["SearchIndex"] = $department;
$slug["Condition"] = 'All';
$slug["Keywords"] = $query;
$params["ItemPage"] = 1;
$slug["TruncateReviewsAt"] = '500';
$slug["ResponseGroup"] = 'Images,ItemAttributes,EditorialReview';
$slug["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z",$time);
$slug["Version"] = "2011-08-01";
ksort($slug);
$query_slug = array();
foreach ($slug as $slugs=>$value)
{
$slugs = str_replace("%7E", "~", rawurlencode($slugs));
$value = str_replace("%7E", "~", rawurlencode($value));
$query_slug[] = $slugs."=".$value;
}
$query_slug = implode("&", $query_slug);
$signinurl = $method."\n".$host."\n".$uri."\n".$query_slug;
$signature = base64_encode(hash_hmac("sha256", $signinurl, $secretkey, True)); // Get Amazon Signature API
$signature = str_replace("%7E", "~", rawurlencode($signature));
$request = "http://".$host.$uri."?".$query_slug."&Signature=".$signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
?>


来源:https://stackoverflow.com/questions/433104/how-do-i-get-a-book-graphic-and-description-from-the-amazon-book-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!