Amazon产品API与PHP

Amazon产品API与PHP,php,curl,amazon-web-services,amazon-product-api,Php,Curl,Amazon Web Services,Amazon Product Api,我正在尝试将Amazon产品API集成到我的网站中,遇到了一些帮助我构建URL的帖子。唯一的问题是,当我执行下面的代码时,会出现以下错误。我做错什么了吗 内部服务器错误服务器 遇到内部错误或错误 配置错误,无法恢复 完成您的请求。请联系 服务器管理员, awsadmin@amazon.com并通知他们 错误发生的时间,以及 你可能做的任何事都可能 造成错误的原因。更多 有关此错误的信息可能是 可在服务器错误日志中找到 编辑 以上代码现在可以工作了……我在基本URL后缺少了一个“?” $AWS_A

我正在尝试将Amazon产品API集成到我的网站中,遇到了一些帮助我构建URL的帖子。唯一的问题是,当我执行下面的代码时,会出现以下错误。我做错什么了吗

内部服务器错误服务器 遇到内部错误或错误 配置错误,无法恢复 完成您的请求。请联系 服务器管理员, awsadmin@amazon.com并通知他们 错误发生的时间,以及 你可能做的任何事都可能 造成错误的原因。更多 有关此错误的信息可能是 可在服务器错误日志中找到

编辑

以上代码现在可以工作了……我在基本URL后缺少了一个“?”

$AWS_ACCESS_KEY_ID = "[myaccesskeyhere]";
$AWS_SECRET_ACCESS_KEY = "[mysecretkeyhere]";

$base_url = "http://ecs.amazonaws.com/onca/xml?";
$url_params = array('Operation'=>"ItemSearch",'Service'=>"AWSECommerceService",
 'AWSAccessKeyId'=>$AWS_ACCESS_KEY_ID,'AssociateTag'=>"yourtag-10",
 'Version'=>"2006-09-11",'Availability'=>"Available",'Condition'=>"All",
 'ItemPage'=>"1",'ResponseGroup'=>"Images,ItemAttributes,EditorialReview",
 'Keywords'=>"Amazon");

// Add the Timestamp
$url_params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());

// Sort the URL parameters
$url_parts = array();
foreach(array_keys($url_params) as $key)
    $url_parts[] = $key."=".$url_params[$key];
sort($url_parts);

// Construct the string to sign
$string_to_sign = "GET\necs.amazonaws.com\n/onca/xml\n".implode("&",$url_parts);
$string_to_sign = str_replace('+','%20',$string_to_sign);
$string_to_sign = str_replace(':','%3A',$string_to_sign);
$string_to_sign = str_replace(';',urlencode(';'),$string_to_sign);

// Sign the request
$signature = hash_hmac("sha256",$string_to_sign,$AWS_SECRET_ACCESS_KEY,TRUE);

// Base64 encode the signature and make it URL safe
$signature = base64_encode($signature);
$signature = str_replace('+','%2B',$signature);
$signature = str_replace('=','%3D',$signature);

$url_string = implode("&",$url_parts);
$url = $base_url.$url_string."&Signature=".$signature;
print $url;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$xml_response = curl_exec($ch);
echo $xml_response;
对于任何想知道的人。然后可以使用simplexml导航xml_响应

希望这有助于其他人:)

对于任何想知道的人。然后可以使用simplexml导航xml_响应


希望这对其他人有所帮助:)

在Amazon产品API中使用以下代码:

<?php
//Enter your IDs
define("Access_Key_ID", "[Your Access Key ID]");
define("Associate_tag", "[Your Associate Tag ID]");

//Set up the operation in the request
function ItemSearch($SearchIndex, $Keywords){

//Set the values for some of the parameters
$Operation = "ItemSearch";
$Version = "2013-08-01";
$ResponseGroup = "ItemAttributes,Offers";
//User interface provides values
//for $SearchIndex and $Keywords

//Define the request
$request=
     "http://webservices.amazon.com/onca/xml"
   . "?Service=AWSECommerceService"
   . "&AssociateTag=" . Associate_tag
   . "&AWSAccessKeyId=" . Access_Key_ID
   . "&Operation=" . $Operation
   . "&Version=" . $Version
   . "&SearchIndex=" . $SearchIndex
   . "&Keywords=" . $Keywords
   . "&Signature=" . [Request Signature]
   . "&ResponseGroup=" . $ResponseGroup;

//Catch the response in the $response object
$response = file_get_contents($request);
$parsed_xml = simplexml_load_string($response);
printSearchResults($parsed_xml, $SearchIndex);
}
?>

对亚马逊产品API使用以下代码:

<?php
//Enter your IDs
define("Access_Key_ID", "[Your Access Key ID]");
define("Associate_tag", "[Your Associate Tag ID]");

//Set up the operation in the request
function ItemSearch($SearchIndex, $Keywords){

//Set the values for some of the parameters
$Operation = "ItemSearch";
$Version = "2013-08-01";
$ResponseGroup = "ItemAttributes,Offers";
//User interface provides values
//for $SearchIndex and $Keywords

//Define the request
$request=
     "http://webservices.amazon.com/onca/xml"
   . "?Service=AWSECommerceService"
   . "&AssociateTag=" . Associate_tag
   . "&AWSAccessKeyId=" . Access_Key_ID
   . "&Operation=" . $Operation
   . "&Version=" . $Version
   . "&SearchIndex=" . $SearchIndex
   . "&Keywords=" . $Keywords
   . "&Signature=" . [Request Signature]
   . "&ResponseGroup=" . $ResponseGroup;

//Catch the response in the $response object
$response = file_get_contents($request);
$parsed_xml = simplexml_load_string($response);
printSearchResults($parsed_xml, $SearchIndex);
}
?>


我正在用它进行测试,但它说我们计算的请求签名与您提供的签名不匹配。检查您的AWS秘密访问密钥和签名方法。有关详细信息,请参阅维修文档。尽管我对这个url的密钥测试工作正常。有什么帮助吗?此代码中的签名失败,因为
ResponseGroup
部分中的逗号不是URL编码的。在另一个
str_replace
之后添加这一行,它就可以正常工作了<代码>php$string_to_sign=str_replace(',','%2C',$string_to_sign)我正在用这个进行测试,但是它说我们计算的请求签名与您提供的签名不匹配。检查您的AWS秘密访问密钥和签名方法。有关详细信息,请参阅维修文档。尽管我对这个url的密钥测试工作正常。有什么帮助吗?此代码中的签名失败,因为
ResponseGroup
部分中的逗号不是URL编码的。在另一个
str_replace
之后添加这一行,它就可以正常工作了<代码>php$string_to_sign=str_replace(',','%2C',$string_to_sign)