0

I want get a "buy now" link and the actualy amazo price of a gaming product get with a game-title. For that i must use the "Search by title" ( http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_SearchingbyTitle.html ).

I found a example for a XML-Request and try to build it for me.

The Example was:

    $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);

That works perfect, but not with my search values. I edit the params and the request is broken.

My request:

    $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);

Why my request not work?

Thanks

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
user1878413
  • 1,813
  • 4
  • 18
  • 24

1 Answers1

1

There's two potential problems that I'm seeing here. The first is that "Game" doesn't seem to be a valid input for SearchIndex, but VideoGames is what you're looking for. See here for a list of all of them.

(Outside the US can find applicable lists here)

The other potential problem I see, and I'm not sure how flexible Amazon's API is with this, is that there is supposed to be a space in the game titled "Payday 2". Which actually brings up a more important consideration than fixing the space. Depending on how much control you have over the entry of the title into whatever you're coding, it might be more flexible to do a search based on keyword instead of title.

JR Warren
  • 317
  • 2
  • 12
  • Edit the SearchIndex, but its not work: "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.". The Signature and Keys are correctly. – user1878413 Aug 17 '13 at 14:05
  • Is that a different error or the same one you were getting before? That seems like a different issue than I was thinking. Also, does it still work with the original search query or do neither work now? A couple of fairly common mistakes to check along those lines: Make sure you didn't switch the key id and the secret key - they're easy to reverse accidentally. And double check in your account to make sure that pair is still active. @user1878413 – JR Warren Aug 17 '13 at 17:21