Amazon Plugin Authorization

Oh, it’s confusing how often Amazon changes it’s product names and API. In my plugin the Help response group is used for key validation, alas recently it’s been deprecated. I need more time to look for an alternative. In the meantime you can hack it by adding a file amtap-aws-key-verification.txt in the wp-content/cache folder where the content is true.

Starting August 15th, the AWS Product Advertising API, as the former E-Commerce Service is now called, will only accept signed requests. The plugin will stop working if you don’t update. Thus I needed to re-engineer a few functions of my WordPress Amazon Machine Tags Plugin.

What you need to do is:

  • Update to version 3.0 of the plugin.
  • If you didn’t adapt any files just overwrite them. If you customized the CSS or XSL files, take care that you don’t overwrite yours. Also the XSL namespace must reflect the API version used in the plugin (2009-07-01), i.e. xmlns:aws= "http://webservices.amazon.com/ AWSECommerceService/ 2009-07-01"
  • Get your Secret Access Key in addition to your existing Access Key ID. Your future requests will be signed using the secret key.
  • Go to the plugin’s admin interface and enter the secret key.
  • Some people experienced a few minutes where the items didn’t show up, instead they got the untransformed XML code. After a few minutes the problem resolved itself. My guess is that Amazon cached the XSL files, the versions mismatched, therefore the XML wasn’t transformed. That’s why I renamed the XSL files so that the new ones will be used. If you want to be sure, also delete the cached files amtap-aws-items-for-post-*.html in your wp-content/cache directory.

If you encounter any problems with the update, re-install the old version and let me know what went wrong so that we can fix it together until August 15th.

You can also support the plugin by translating it. There’s an empty PO file in the package. With a tool such as Poedit it’s fairly easy to translate everything. Thanks. ;)

51 Responses to ‘Amazon Plugin Authorization’

  1. Fred

    Martin,

    My keys are failing validation on the admin page.

  2. Martin Kliehm

    @Fred, your Access Key ID should be 20 characters long and your secret key 40 characters. You can test your keys with an Amazon tool.

    Your secret key is used to build a SHA256-encoded hash key, and since it worked for mine and uses an open source function for encryption I don’t believe there’s an error with that part. What’s the error message? Do you use the original XSL files or your own?

  3. Joe

    Hi. Thanks for this update – it’s great to have this plugin ready for the Amazon changes.

    I accidentally overwrote my old settings and my site is now displaying the plugin’s default LowestNewPrice rather than the ListPrice I had enabled before (should have backed up, I know…). I’ve changed the former for the latter whenever (I think) it appears in the amtap-html-content.xsl file, but I’ve still not managed to get it displaying the correct list price. I’ll keep looking at it, because I’m sure I’ve missed something obvious.

    Can I make a suggestion for a future revision? If you were to allow a way to edit which prices are shown, plus the ability to choose image sizes, star ratings etc, via the WordPress admin interface, it would be so much more idiot-proof for idiots such as myself who don’t see xslt as a natural habitat.

    Joe

  4. Martin Kliehm

    I’d like to sum-up a few bug reports I received because they all had the same problem: All received the error message “The access key or the secret key you entered is invalid. Please double-check it.” The reason is probably not your key, but the timestamp. In wp-content/ cache/ amtap-aws-key-verification.txt they got an error message “Timestamp […] is more then 900 seconds before current time […]

    Apparantly the server time, the server timezone offset as well as the WordPress timezone offset is relevant. I hope I fixed that now by taking the GMT for the timestamp in plugin version 3.0.2. Well, at least I compared my code with another plugin’s code, and the GMT offset was the only difference, except that my code works with PHP 4 and 5. ;)

    I’m sorry for the inconvience, the Amazon developer manual was somewhat unclear about this. If you still have verification problems, please let me know (a screenshot of the timezone setting in your blog’s general settings panel plus pasting the content of amtap-aws-key-verification.txt or one of the cached HTML files will help).

  5. Bryan Villarin

    @Martin Kliehm — Awesome work on figuring it out so quickly. That did the trick. Thanks!

  6. Lefteris

    Thanks for the update but… I do not understand why this tendency of adding new css files to be loaded in the head. I think you could easily add the option to bypass this feature.

  7. Martin Kliehm

    @Joe, @Lefteris, thanks for the suggestions. When the authorization is working I’ll add a few fields to the admin interface to make the CSS file optional for those who know how to style it in a theme, and to allow some variation in the price or image selection.

  8. Fred

    Thanks Martin, that last update did the trick!

  9. Johannes

    The page on my server crashes after updating the plugin. The execution just stops somewhere while giving out the content. errorreporting set to EALL – No error. php_memory set to 128mb – still crashes.

    if i deactivate the amazon machine tags the page reappears.

    i can reach the admin backend interface: If i update the keys, the admin panel dies somewhere while building up the left navigation…

    any idea where i could take a look what runs wrong?

    Thanks from salzburg,

    Johannes

  10. Johannes

    Hi Martin -

    after debugging awhile, i pinned down the cause of the output process abortion: It’s the line $hmac = pack(‘H*’, $hashfunc(….)); in function hmacsha1($key, $data) which kills the php process or something like that.

    an echo+die before the pack call displays – a echo+die after that doesn’t appear: the whole process dies. Since i don’t have the slightest clue what you do there i kindly ask for assistance ;-)

    greets from Salzburg,

    Johannes

  11. Martin Kliehm

    Thanks Johannes for the feedback. You are actually the second person to report this. I’ll look into the issue tomorrow morning. Which version of PHP do you use? And how many Amazon items are there in your sidebar? It seems that the encryption has to do some heavy lifting…

  12. Carsten

    Hey Martin, thanks for the quick turn-around. 3.0.2 works beautifully.

  13. Reginald

    Greetings… I upgraded without backing up anything and I remember I struggled with the original plugin. I’m not sure where “the XSL namespace must reflect the API version used in the plugin (2009-07-01),[…]”, belongs.

    The plugin is being used at environmentaide.org. It looks to be working although I’m not sure. I never heard of any sales with the old plugin that was there for around a year, and was never sure that was working either…

  14. judy

    Hi, The plugin don’t work for me ,nothing show in my sidebar,I use 000webhost free space maybe it doesn’t support this plugin,I’m not sure,could you give me some suggestions?thank you.

  15. Martin Kliehm

    @Reginald apparently the plugin works. The items are displayed in your page, and your associate ID is in the URL to Amazon. Like I said, if you haven’t written your own XSL files just ignore the namespace section.

    @Judy, items show up in the sidebar when your keys are valid, when there is the PHP snippet in sidebar.php, and when you use tags in the form book:isbn=1234567890. The plugin doesn’t work with widgets yet, maybe that’s the reason.

  16. judy

    Thank you for your reply.when I add book:isbn=1234567890 in article,there is one item show up in the post,but still not show in sidebar,I’ve already add code in sidebar.php.

  17. Spencer

    Hey, I’ve been using the plugin for a few months now. A week or so ago it stopped working briefly, then recovered. A few days later it ceased again and now I can’t get my Access Key to validate. I’ve tried the update with the secret key generated from the AWS account with no success until I changed the time-zone in my general settings on wordpress. It worked again for about 24 hours. Since, I have tried re-installing the older version, emptying the cache and reinstalling the new version, etc. The thing that remains the same is that my access key returns invalid. Any help would be very appreciated.

  18. Martin Kliehm

    @judy, the code snippet <?php AMTAP::get_items(); ?> belongs in sidebar.php while book:isbn=1234567890 is a tag for that post. I’m not sure if that was clear. Also the plugin currently does not work with widgets, i.e. if you have enabled widgets anything that you write into sidebar.php will be ignored.

    @Spencer, usually a server is set to UTC (= GMT) time. The plugin doesn’t do anything with the WordPress timezone adjustment setting, so this doesn’t have any effect. It just reads the server time and timezone and calculates the UTC time. If you still get false errors about your key being invalid, please check amtap-aws-key-verification.txt. There should be the original error message from Amazon in there. Please compare the time in the error message with your server time and timezone. That should give us a clue what’s wrong.

  19. Sebastian

    Hello,

    can you say how I can change the language or better the default country because I want that all articles are shown in € not $

    Regards Sebastian

  20. Martin Kliehm

    @Sebastian, there’s an option for setting the default country in the plugin’s settings.

    Also unfortunately I’m going to have an acute disc prolapse operated tomorrow, so please have patience within the next weeks as I won’t be able to check mails quite so often.

  21. Donald Burr

    Hi Martin, thanks for your quick action in fixing the Amazon Machine Tags plugin with respect to the localtime-vs-UTC issue. The latest version is running very nicely now.

    One minor gripe tho is when you tag an item that doesn’t have a preview image on Amazon. This happens a lot on pre-release items, but you see it sometimes on released products as well. Especially when I have a couple of products tagged, and one or more of them doesn’t have an image associated with it, it looks kinda weird on my page and breaks up the formatting. I wonder if it would be possible for the Machine Tags to detect these and insert its own “image not available” type graphic?

  22. Martin Kliehm

    @Donald that’s a good idea and easy to implement. Could you give me an example for such an item (ASIN)? I guess the image attributes in the XML are just empty then and I can set a default. What does Amazon use? A b/w Amazon logo on a gray background might be good…

  23. alondans

    Hi

    is there a way to
    a) make the image preview of the product smaller?
    b) get rid of the text besides it?

    Something else.. I just saw..it is showing the wrong price for the product. german amazon..however..totally wrong price on the side

    Rob

  24. Martin Kliehm

    @Rob, unfortunately I can’t look into the source code as I’m stuck with my iPhone this week, but currently the only way to change the image size and which prize is selected can only be edited in the XSL files. I used XSL for exactly that purpose and kept it out of PHP, but it turned out that most people are overchallenged editing XSL. Therefore I will probably add some options in a future release. Currently I’d like to ask you to look up the appropriate XML selectors in the comments of the old plugin post.

  25. alondans

    hi

    Are there restrictions, like I only can put 10 of the [amtap amazon:asin=B00005UQZ6] onto one site? because after 10..non of the others are shown

    Alon

  26. Martin Kliehm

    Alon, right, the API has a limit of ten requests. But that’s another question already answered in the comments of the old post. I’d suggest to check the comments there first before we build up a hundred redundant requests here. Thanks. ;)

  27. alondans

    I am sorry…I hope nobody asked this until now ;)

    How can I put an link into a sidebar widget, like the text widget? Is that possible?

    Alon

  28. Martin Kliehm

    No, this plugin doesn’t work with widgets yet.

  29. Anthony

    Great plugin Martin. Worked first time for me. Any chance of publishing a widget? I realize it’s relatively simple to put the PHP code in the sidebar. But I read quite often and would like a “Currently Reading” Widget in my sidebar. Changing the php for this everytime would get annoying, I think.

  30. John

    Hi Martin, I started using the plugin a few days ago, and it was working great. Now, it seems that the [amtap amazon:asin=xxxxxxx] tags are getting parsed, but are being replaced with nothing (I checked the HTML source as well). I have double checked all the usual things – using 3.0.2, checked cache directory, checked AWS indentifiers, removed the plugin, reinstalled, etc., but no luck.

    The strange thing is, the web service calls seem to be completing – the cache directory is getting filled with valid data. I can even echo $sItems after this line in the code:

    $sItems = AMTAP::get_items( $aMatches[1], ‘content’ );

    and it dumps the XML data returned. It just doesn’t seem to be making it to the final page display for some reason. I have tried it with multiple WP themes, as well.

  31. Christian

    I’ve just updated to 3.0.2 and got a strange behavior : all notes with several machine tags in it are working fine, while nothing is displayed when there is only one tag in the note.

    Any idea ?

  32. Christian

    After debugging around, I found that the generated signature is not correct when there is one tag, and ok otherwise. As in an earlier comment of Johannes, I think the problem is in the hmacsha1 function, probably related to the length of the string since I managed to workaround by changing the AMTAPHeadline string to a shorter one (actually just on char). Works for me, but just a workaround.

    Hope it helps. Thanks for this very useful plugin.

  33. Thomas

    Hey, I’ve got a big problem with editing the templates: Changes on the xsl files don’t take effect. I deleted them and the plugin still works and looks the same as before.

    And my second problem is: I need two content templates, one should only display an image and another should display title, price and the link to amazon. Can you please help me?

    Thanks!

  34. Johnny

    hi,

    my keys are failing when i enter them in. i read above that it might be a timestamp issue?

    http://learningtheworld.eu/2009/amazon-authorization/#comment-37322

    I wasn’t sure what the solution was to fix this. any help would be greatly appreciated.

    thanks!

  35. Philippe Hilger

    Hi Martin.

    Congrats for the great plugin. I used to use it on my blog before moving to WP MU (and had left free the fields for Gemany/Japan/UK for you to earn some pennies…). Unfortunately, since the move the plugin is not working anymore, mainly because I couldn’t configure it. There is a small difference about the options pages between WP and WP MU, and I’m sure a minor change would resolve this situation.

    If you got some spare time to correct this issue, I’ll be able to give you some clues (I had to adapt my own skloogs-megasena plugin for MU). Otherwise I’ll try and make the changes myself and will forward them to you.

    Best Regards, Phil.

  36. Gregory Foster

    Hi Martin, Thank you for a very useful plugin. Just got it working in the sidebar on a new 2.8.6 WP installation. I ran into a problem worth mentioning. If your server timeclock is incorrect, and outside the bounds of Amazon’s current timestamp, requests to verify one’s credentials/access keys will fail. An error message will be displayed on the Amazon Machine Tags settings page indicating there was a problem with the credentials. I checked the XML response file you so thoughtfully save in the cache, and observed the Amazon error code AWS.TimestampExceedsTimeToLive and the error message “Timestamp 2009-11-30T00:21:53Z is more then 900 seconds before current time 2009-11-30 03:29:39Z.” Sure enough, I checked my server clock and it was off by 3 hours. Setting the correct server time and refreshing the Amazon Machine Tags settings page fixed the problem.

    Thanks for a sweet plugin!

  37. Carsten Knoch

    Hey Martin,

    I’ve been noticing something that’s a little puzzling to me. I connect to regular old amazon.com to get CD and book cover images using Amazon Machine Tags.

    The prices it retrieves are typically lower than than price actually listed when you click through to Amazon. What is the price the plugin retrieves? Am I missing something configuration detail?

    Let me know what I might be doing wrong… Thanks.

  38. MJ

    Hi Martin, Great job! I love the plugin, installed it with ease.

    The one challenge I’m still having is how to access the XML to change the image size from small to medium. I have the “debug” box checked in the options. But when I bring up the HTML sourcecode for the posts (I’m using Amazon Machine Tags in the post, not the sidebar), I don’t see the commented links that you mentioned in previous responses.

    Am I looking in the right place?

    And, once I find the XML files, do I have to change them one at a time? Or is there a global setting I can switch?

    Thanks! MJ

  39. Maike

    Hey, I’ve got a very big problem with mytemplates. any changes on the xsl files don’t take any effect. Best Regards

  40. Wolfgang

    Special words in article prevent displaying covers and all info from amazon

    Hello,

    I got the problem, that there are some stop words, which prevent the Plugin working properly, e.g. casino, krasinski and some other. Probably this is something amazon has included but it is really annoying because it means I cannot write about the movie “casino royale” or the actor “John Krasinski”. Covers aren´t displayed / No link to amazon :-(

    Can anyone confirm this and has got the same problem? Is there a workaround?

  41. Bryce

    I just installed Amazon Machine Tags on my WordPress 2.9.1 blog, and set all the configuration options, but it doesn’t seem to work. Nothing shows up in a post or page when I put a tag there, and the tag itself shows up in the sidebar if I place it in a widget. Can you help me troubleshoot this?

  42. Erik

    Does this plugin not work with WordPress 2.9.1? I can’t get amazon machine tags to show up on any pages anymore since the update. Is there a fix for this planned?

  43. Martin Kliehm

    Sorry for the delay. I just upgraded to WordPress 2.9.1, and everything works fine. I think a problem might be that the WordPress upgrade process asks you to delete wpcontent/cache, so the folder is gone and with it all folder permission settings. You probably have to create the folder again and set the read/write permissions accordingly (or next time, just delete the cache folder contents, but keep the folder intact). Also the plugin writes a text file as confirmation that the key has been validated into the same folder. I admit this is annoying when you upgrade WordPress as that requires you to run the validation again on the plugin’s options page after you upgraded. It seemed like a reasonable idea to keep all files in an existing cache folder when I wrote the plugin, but looking back it would be better to keep the confirmation file in the plugin’s folder. I’ll fix that in a future version. :(

  44. Josiah Staggs

    Hey Martin,

    I love the plugin! I’m working on a new site that will be selling products that are listen on amazon. The only thing i need from Amazon as of now is the price of individual items. I’m wondering how i can go about ONLY pulling the price of a product and leaving the rest out. I hope you have the time to reply back. I’m not much of a coder so this basically a plea lol

  45. Martin Kliehm

    Hi Josiah,

    if you look into the XSL files (amtap-html-content.v3.xsl and amtap-html-sidebar.v3.xsl) you’ll see commented blocks of XSL code. If you don’t want an image, remove the <xsl:element> code block beneath the comment <-- Item image -->. There’s also a block titled “Price,” where different prices are pulled in. If you change the XSL I’d recommend to save a working copy of the file first. After you have changed it, validate that the document is still well-formed (only check the well-formed checkbox). Also it seems like Amazon (and my plugin) caches your request, so set the cache age option to “1” and be patient for a few minutes until the Amazon proxy requests a new XSL file.

    If that sounds too complicated: yes, I agree. ;) I’m considering an optional set-up where users can choose which items they would like to show along with their price preferences etc., but I can’t predict when I will find the time…

  46. Gary Griswold

    The shorttag into a post works consistently for me, but the machine tags into the sidebar only seems to work with some themes. This is true even though, I have embedded the snippet of code into the sidebar.php of each theme tried. Is there any help that you can offer to explain why this might be true, or what might be done about it? Also, it is unclear why the snippet of code in the side bar is required. Why doesn’t an add_action work? It seems like the correct solution to all of this is a widget. So, it would be helpful to understand what code would need to be executed by the widget.

  47. Boban Alempijevic

    Hi Martin,

    I just installed your plug-in and got my self an account with Amazon Web Services. I entered the Access Key ID and the Secret Access Key in the config fields. When I updated the settings I got an error I am pretty sure I cant do anything about, but I will still ask here if anyone knows a work around…

    “Your server is located in a private IP address space. Amazon Web Services cannot fetch the file that is required to validate the access key.”

    I am running my site on servage.net

  48. Starry Night

    Is this plugin compatible with WPMU? I was unable to update settings in the WP admin panel (I had to add them directly into the database). When I try to update options it redirects to http://popmagick.com/wp-admin/options.php and gives the error “Error! Options page not found.”

    Having added [amtap amazon:asin=1592575331] to a post, it doesn’t display after being published: http://popmagick.com/complete-idiots-guide-to-wicca-and-witchcraft/

    I have got this working correctly on another website (vanilla WP, not WPMU), so I suspect it isn’t working with MU. Any suggestions?

  49. Ulrik

    Hello, Nice plug-in btw. But I don’t understand the “IP 2 Country” instructions! He just writes > “Create the table ‘iptocountry’ to store the database:” WHAT ? WHERE?

    Thanks.

  50. Thomas

    Prima, ruck zuck installiert in der Sidebar. Wie wäre es denn mit einem Widget für die Sidebar, in das man die ISBN-Nummern einträgt?

  51. Marcus

    sehr gutes Plugin, sehr schnell installiert. Thank you very much! LG Marcus