0

我想要一个“立即购买”链接,并且游戏产品的实际亚马逊价格与游戏名称一起获得。为此,我必须使用“按标题搜索”(http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_SearchingbyTitle.html)。

我找到了一个 XML-Request 的示例并尝试为我构建它。

示例是:

    $AWSAccessKeyId = "";
$SecretAccessKey = "";

$ItemId = "0679722769"; // ASIN
$Timestamp = gmdate("Y-m-d\TH:i:s\Z");
$Timestamp = str_replace(":", "%3A", $Timestamp);
$ResponseGroup = "ItemAttributes,Offers,Images,Reviews";
$ResponseGroup = str_replace(",", "%2C", $ResponseGroup);

$String = "AWSAccessKeyId=$AWSAccessKeyId&
AssociateTag=xy&
ItemId=$ItemId&
Operation=ItemLookup&
ResponseGroup=$ResponseGroup&
Service=AWSECommerceService&
Timestamp=$Timestamp&
Version=2009-01-06";



$String = str_replace("\n", "", $String);

$Prepend = "GET\nwebservices.amazon.com\n/onca/xml\n";
$PrependString = $Prepend . $String;

$Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True));  
$Signature = str_replace("+", "%2B", $Signature);
$Signature = str_replace("=", "%3D", $Signature);

$BaseUrl = "http://webservices.amazon.com/onca/xml?";
$SignedRequest = $BaseUrl . $String . "&Signature=" . $Signature;

$XML = simplexml_load_file($SignedRequest);

echo '<a href="'.$SignedRequest.'">XML</a><p>';
print_r ($XML);

这很完美,但不适用于我的搜索值。我编辑了参数并且请求被破坏了。

我的请求:

    $AWSAccessKeyId = "";
$SecretAccessKey = "";

$ItemId = "Payday2"; // ASIN
$Timestamp = gmdate("Y-m-d\TH:i:s\Z");
$Timestamp = str_replace(":", "%3A", $Timestamp);
$ResponseGroup = "ItemAttributes";
$ResponseGroup = str_replace(",", "%2C", $ResponseGroup);

$String = "AWSAccessKeyId=$AWSAccessKeyId&
AssociateTag=xy&
Operation=ItemSearch&
SearchIndex=Game&
Title=$ItemId&
ResponseGroup=$ResponseGroup&
Service=AWSECommerceService&
Timestamp=$Timestamp&
Version=2009-01-06";



$String = str_replace("\n", "", $String);

$Prepend = "GET\nwebservices.amazon.com\n/onca/xml\n";
$PrependString = $Prepend . $String;

$Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True));  
$Signature = str_replace("+", "%2B", $Signature);
$Signature = str_replace("=", "%3D", $Signature);

$BaseUrl = "http://webservices.amazon.com/onca/xml?";
$SignedRequest = $BaseUrl . $String . "&Signature=" . $Signature;

$XML = simplexml_load_file($SignedRequest);

echo '<a href="'.$SignedRequest.'">XML</a><p>';
print_r ($XML);

为什么我的请求不起作用?

谢谢

4

1 回答 1

1

我在这里看到了两个潜在的问题。首先是“游戏”似乎不是 SearchIndex 的有效输入,但 VideoGames 是您正在寻找的。有关所有这些的列表,请参见此处。

(美国以外可以在这里找到适用的列表

我看到的另一个潜在问题,我不确定亚马逊的 API 在这方面有多灵活,游戏中应该有一个名为“发薪日 2”的空间。这实际上带来了比固定空间更重要的考虑。根据您对将标题输入到您正在编码的任何内容中的控制程度,基于关键字而不是标题进行搜索可能会更灵活。

于 2013-08-16T15:48:53.303 回答