获得使用亚马逊的API产品的详细信息 [英] Getting product details using Amazon API
问题描述
我有以下code输出从亚马逊的项目清单,但我不知道如何访问特定的产品(综述,评论等)。任何帮助将是AP preciated。
< PHP
功能makeAWSUrl($参数,$ associate_tag,$ access_key,$ SECRET_KEY,$ aws_version ='2009-06-01'){
$主机='ecs.amazonaws.com';
$ PATH ='/ onca / xml的';
$查询=阵列(
'服务'=> AWSECommerceService,
AWSAccessKeyId'=> $ access_key,
AssociateTag'=> $ associate_tag,
'时间戳'=> gmdate(Y-M-D \ TH:我:秒\ Z'),
'版本'=> $ aws_version,
);
//合并中被传递的任何选项
如果(is_array($参数)){
$查询= array_merge($查询,$参数);
}
//做一个不区分大小写的,自然顺序排序的数组键。
ksort($查询);
//创建可签名的字符串
$ TEMP =阵列();
的foreach($查询为$ K => $ V){
$临时[] = str_replace函数(%7E','〜',rawurlen code($ K))。 '='。 str_replace函数(%7E','〜',rawurlen code($ V));
}
$可签名=破灭('和;',$ TEMP);
$ stringToSign =GET \ n $的主机\ n $的路径\ n $可签名的;
//哈希AWS密钥,并生成请求签名。
$ hex_str = hash_hmac('SHA256',$ stringToSign,$ SECRET_KEY);
$生='';
为($ i = 0; $ I< strlen的($ hex_str); $ I + = 2){
。$生= CHR(hexdec(SUBSTR($ hex_str,$ 1,2)));
}
$查询['签名'] = base64_en code($生);
ksort($查询);
$ TEMP =阵列();
的foreach($查询为$ K => $ V){
$临时[] = rawurlen code($ K)。 '='。 rawurlen code($ V);
}
$最后=破灭('和;',$ TEMP);
回归HTTP://。 $主机。 $路径。 ? 。 $决赛;
}
$ URL = makeAWSUrl(阵列('关键词'=>'的iPod,
操作=> ItemSearch,
SearchIndex'=> 电子),
ResponseGroup'=> '中',
'someid','aaaaaaaaaaaaa','aaaaaaaaaaaaaaaaaaaaaaaaaaa');
$响应=使用simplexml_load_file($网址);
的foreach($响应 - >物品─>项目为$项)
{
$标题[] = $本期特价货品> ItemAttributes->标题;
}
的foreach($标题为$ CurrentTitle)
{
回声&其中; H2>中$ CurrentTitle。&所述; / H 2>中;
}
?>
在 $响应 - >物品─>项目
列表中包含的所有项目/物品匹配您的查询。这是的对象列表。每一个这样的对象有像 ItemAtributes
属性这agains可以有属性。
看一看的<一个href="http://docs.amazonwebservices.com/AWSEcommerceService/4-0/ApiReference/MediumResponseGroup.html">documentation看看哪些属性avalable。例如 ItemAttributes-&GT; ListPrice-&GT;金额
包含该项目的价格
因此,例如,为每个结果产出价格和标题更改code到
$响应=使用simplexml_load_file($网址);
的foreach($响应 - &GT;物品─&GT;项目为$项){
回声&LT; H2&gt;中$本期特价货品&GT;。ItemAttributes-&GT;名称&LT; / H2&gt;中;
回声价格:$本期特价货品&GT; ItemAttributes-&GT; ListPrice-&GT;金额。
}
I've got the following code to output a list of items from amazon, but I not sure how to access specific products (with Summery, reviews, etc). Any help would be appreciated.
<?php
function makeAWSUrl($parameters, $associate_tag, $access_key, $secret_key, $aws_version = '2009-06-01') {
$host = 'ecs.amazonaws.com';
$path = '/onca/xml';
$query = array(
'Service' => 'AWSECommerceService',
'AWSAccessKeyId' => $access_key,
'AssociateTag' => $associate_tag,
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version' => $aws_version,
);
// Merge in any options that were passed in
if (is_array($parameters)) {
$query = array_merge($query, $parameters);
}
// Do a case-insensitive, natural order sort on the array keys.
ksort($query);
// create the signable string
$temp = array();
foreach ($query as $k => $v) {
$temp[] = str_replace('%7E', '~', rawurlencode($k)) . '=' . str_replace('%7E', '~', rawurlencode($v));
}
$signable = implode('&', $temp);
$stringToSign = "GET\n$host\n$path\n$signable";
// Hash the AWS secret key and generate a signature for the request.
$hex_str = hash_hmac('sha256', $stringToSign, $secret_key);
$raw = '';
for ($i = 0; $i < strlen($hex_str); $i += 2) {
$raw .= chr(hexdec(substr($hex_str, $i, 2)));
}
$query['Signature'] = base64_encode($raw);
ksort($query);
$temp = array();
foreach ($query as $k => $v) {
$temp[] = rawurlencode($k) . '=' . rawurlencode($v);
}
$final = implode('&', $temp);
return 'http://' . $host . $path . '?' . $final;
}
$url = makeAWSUrl(array('Keywords' => 'ipod',
'Operation' => 'ItemSearch',
'SearchIndex' => 'Electronics'),
'ResponseGroup' => 'Medium',
'someid', 'aaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaaaaa');
$response = simplexml_load_file($url);
foreach ($response->Items->Item as $item)
{
$Title [] = $item->ItemAttributes->Title;
}
foreach($Title as $CurrentTitle)
{
echo "<h2>".$CurrentTitle."</h2>";
}
?>
The $response->Items->Item
list contains all the items/articles which matches your query. This is a list of objects. Each of this objects got properties like ItemAtributes
which agains can have properties.
Have a look at the documentation to see which attributes are avalable. For example ItemAttributes->ListPrice->Amount
contains the price of the item.
So for example to output price and title for each result change the code to
$response = simplexml_load_file($url);
foreach ($response->Items->Item as $item) {
echo "<h2>".$item->ItemAttributes->Title."</h2>";
echo "Price: ".$item->ItemAttributes->ListPrice->Amount;
}
这篇关于获得使用亚马逊的API产品的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!