我想要获得“立即购买”链接以及带有游戏标题的游戏产品的实际亚马逊价格。为此,我必须使用“按标题搜索”( http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_SearchingbyTitle.html )。
我找到了一个 XML 请求的示例,并尝试为我构建它。
示例是:
$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);
为什么我的请求不起作用?
谢谢
我在这里看到两个潜在的问题。首先,“Game”似乎不是 SearchIndex 的有效输入,但 VideoGames 正是您要查找的内容。 请参阅此处查看所有列表。
(美国境外可以在此处找到适用的列表)
我看到的另一个潜在问题是,游戏中应该有一个名为“Payday 2”的空间,我不确定亚马逊的 API 对此有多灵活。这实际上提出了比修复空间更重要的考虑因素。根据您对将标题输入到您正在编码的内容中的控制程度,基于关键字而不是标题进行搜索可能会更灵活。