Hi, I'm running the PHP affiliates 'Accessories Me' amazon script on a few sites. The script comes from here- http://www.accessories.me.uk/about5.htm From the middle of August Amazon requires that requests are signed using an access key, and a secret access key. Has anyone modified their version of this script to include a signing function/s? Can anyone help me modify the script to include necessary function? I'm not particularly PHP savvy and so would be willing to buy someone a few drinks (i'm also poor!) in return for coding something that will allow this script to keep on working. Cheers, John
I have been aware of the 'Accessories Me' amazon script for quite sometime but never used it. However I downloaded it and took a look after reading your post. Thinking it would possibly be pretty easy to update using the code I added at the following thread. http://forums.digitalpoint.com/showthread.php?t=1366791 While I haven't had much time to investigate it looks like the signature code could be added to the parser_functions.php file much like I did with ASM2? As time allows I will see what I can do with the script.
Thanks Myhart. If you do get to play with the script and get it to work, please give me a shout. I've been experimenting with url_functions.php a little bit. John
Ok I have the API Product signature working with my copy of the 'Accessories Me' Amazon script. 1. Add "your" SubscriptionId to the url_functions.php file in each of the the 3 fuctions. 2. Add the code I posted for ASM2 in the parser_functions.php file. The code is added to both the parseXML() and parseProdXML functions right after the global $escUrl; variable. To view the request URL disable the cache and echo the $escUrl variable. Please note that Amazon has new requirements for anyone caching the API feed. So it may be necessary to adjust the cache time? Also Amazon requests that the time that the product API is cached be included with the pricing info displayed on your website.
Thanks myhart, I'm still struggling though. In url_functions.php I added my amazon access key ID in place of the subscription key id that was a previously a defualt code that came with the script for functions browse, product and search, and added your asm2 code in the 2 places you said in parser_functions.php including my access key id and secret access key. I get this error: SimpleXMLElement Object ( [Error] => SimpleXMLElement Object ( => AWS.MissingServiceParameter [Message] => Your request is missing the Service parameter. Please add the Service parameter to your request and retry. ) ) <?xml version="1.0" ?> - <ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2009-01-06/"> - <Error> <Code>SignatureDoesNotMatch</Code> <Message>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.</Message> </Error> <RequestID>c4a2cf24-b1d4-40b7-8eb6-112f884fb840</RequestID> </ItemLookupErrorResponse> Cache is disabled My sites is a UK one with the UK address in constants.php. Do I need to cahnge the com to co.uk in your asm2 code inserts? Thanks for your help- much appreciated and if I can get this to work, i'll get you a couple of drinks by paypal!! John Code (markup):
Try adding the code below with your SecretAccessKey to both funtions (parseXML and parseProdXML) in the parser_functions.php file. You do not need to add your access key id to the code below if it is already included in the url_functions.php file. The UK address should be ok and can be checked by echoing the request url ($escUrl) both before and after the code below. You can uncomment echo '<a href="'.$SignedRequest.'">API</a><p>'; to view the raw XML and check for the signature. // Start API Signature Code Here $SecretAccessKey = ""; $Request = $escUrl; $String = rawurldecode($Request); $String = str_replace("%7E", "~", $String); $String = preg_replace('/[\r\n\" "]/', '', $String); $String = preg_replace('#Keywords=(.*?)&([A-Za-z]+)=#e', '"Keywords=".preg_replace("/[^0-9a-zA-Z]/"," ","$1")."&".$2."=";', $String); $String = preg_replace('/[" "]+/', ' ', $String); $StringArray = explode( '?', $String, 2); $Parameters = explode("&", $StringArray[1]); $Parameters[] = "Timestamp=" .gmdate("Y-m-d\TH:i:s\Z"); asort($Parameters); $NewString = implode("&", $Parameters); $NewString = rawurlencode($NewString); $NewString = str_replace("~", "%7E", $NewString); $NewString = str_replace("%3D", "=", $NewString); $NewString = str_replace("%26", "&", $NewString); $url = parse_url($StringArray[0]); $PrependString = "GET\n" .$url['host']. "\n" .$url['path']. "\n" .$NewString; $Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True)); $Signature = rawurlencode($Signature); $SignedRequest = $StringArray[0]. "?" . $NewString . "&Signature=" .$Signature; //echo '<a href="'.$SignedRequest.'">API</a><p>'; $escUrl = $SignedRequest; // End of API Signature Code Code (markup):
That seems to work great- thank you so much. The xml API output looks fine and amazon seem to be accepting it fine on all the scripts functions. I ran it again with a bad secret access key as a test and it gave a reject error- so i'm quite sure the good one is working- roll on august 15 for the final test! I'm leaving the cache disabled for now but might try with a fresh one after the 15th. PM me your paypal and i'll send you a 'couple of beers'- i'm truly grateful, or I have a couple of good general phpld directories that i'll give you free listings on for your furniture business. Cheers, John