![](/img/trans.png)
[英]php, CodeIgniter- Amazon Product Advertising API, how to get ASIN from a product URL
[英]Amazon get item details by searching ASIN using API PHP/jQuery
我需要通過搜索ASIN獲取Amazon產品詳細信息(商品名稱,品牌,價格等。)。
我查看了Amazon的API,但找不到確切的代碼來做到這一點。 https://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html
我想與PHP或Javascript集成。 有什么幫助嗎? 提前致謝。
這是一個簡單的例子。 您必須將$public_key
, $private_key
和$associate_tag
替換$public_key
您自己的值。我尚未對此進行測試,但是請仔細閱讀並讓我們知道它是否有用。
<?php
include('aws_signed_request.php');
$public_key = '********';
$private_key = '********';
$associate_tag = '********';
// generate signed URL
$request = aws_signed_request('com', array(
'Operation' => 'ItemLookup',
'ItemId' => 'B008GG93YE',
'ResponseGroup' => 'Small'), $public_key, $private_key, $associate_tag);
// do request (you could also use curl etc.)
$response = @file_get_contents($request);
if ($response === FALSE) {
echo "Request failed.\n";
} else {
// parse XML
$pxml = simplexml_load_string($response);
if ($pxml === FALSE) {
echo "Response could not be parsed.\n";
} else {
if (isset($pxml->Items->Item->ItemAttributes->Title)) {
echo $pxml->Items->Item->ItemAttributes->Title, "\n";
}
}
}
?>
aws_signed_request.php代碼
<?php
function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag=NULL, $version='2011-08-01')
{
// some paramters
$method = 'GET';
$host = 'webservices.amazon.'.$region;
$uri = '/onca/xml';
// additional parameters
$params['Service'] = 'AWSECommerceService';
$params['AWSAccessKeyId'] = $public_key;
// GMT timestamp
$params['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
// API version
$params['Version'] = $version;
if ($associate_tag !== NULL) {
$params['AssociateTag'] = $associate_tag;
}
// sort the parameters
ksort($params);
// create the canonicalized query
$canonicalized_query = array();
foreach ($params as $param=>$value)
{
$param = str_replace('%7E', '~', rawurlencode($param));
$value = str_replace('%7E', '~', rawurlencode($value));
$canonicalized_query[] = $param.'='.$value;
}
$canonicalized_query = implode('&', $canonicalized_query);
// create the string to sign
$string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;
// calculate HMAC with SHA256 and base64-encoding
$signature = base64_encode(hash_hmac('sha256', $string_to_sign, $private_key, TRUE));
// encode the signature for the request
$signature = str_replace('%7E', '~', rawurlencode($signature));
// create request
$request = 'http://'.$host.$uri.'?'.$canonicalized_query.'&Signature='.$signature;
return $request;
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.