Rescuscitating AMM with Amazon Web Service signed requests

Wednesday, August 26th, 2009

A few days ago Amazon added a requirement to their AWS that all requests to the service be signed, lest they be rejected. I’ve been using Sozu’s excellent Amazon Media Manager plugin for a while now to manage the currently reading list on this blog. It’s been a great way to keep track of exactly what I have read (avoiding the need to, like, remember), as well as masking my illiteracy by pasting a giant list of what is commonly known as airport trash.

Unfortunately, this is one plugin that hasn’t been updated in quite a while (after all, if ain’t broke…), so it broke. Being the sort of developer that’s quite happy to pick up a block of php and hack it until it works, I stumbled across this blog entitled ‘Amazon® AWS HMAC signed request using PHP‘, which has a function to download.

So to fix AMM:

1. Download that file, and copy the contents into the bottom of amm_parser.php.

2. In the same file (amm_parser.php), replace your _setUrl function with this one:

function &_setUrl() {
	//Build URL from base URL and other required parameters
	switch ($this->_locale) {				
		case 'uk':
			$region = 'co.uk';
			break;
		case 'de':
			$region .= 'de';
			break;
		case 'jp':
			$region .= 'co.jp';
			break;
		case 'fr':
			$region .= 'fr';
			break;
		case 'ca':
			$region .= 'ca';
			break;
		case 'us':
		default:
			$region = 'com';
			break;
	}
	$public_key = "< < Your Access Key ID >>";
	$private_key = "< < Your Secret Access Key >>";
	$url = aws_signed_request($region, array(
			"Operation"=> "ItemSearch",
			"Keywords" => $this->_parameters[Keywords],
			"ResponseGroup"=>$this->_parameters[ResponseGroup],
			"SearchIndex" => $this->_parameters[SearchIndex],
			"AssociateTag" => urlencode($this->_associate_tag)),
			$public_key, $private_key);
	return $url;
}

3. Oddly enough, this new method requires a private secret key which Amazon recommends to not give to anyone. So I’m not going to post mine here, even though it’s required for the plugin to work. So before I ponder that particular nugget of madness, you’ll need to sign up for an AWS developer account, and find your own keys via the Access Identifiers page. These need to be added into the function above.

That should be enough to get you back up and running again, although selfishly I’ve only really tested it for my needs alone. So please let me know if it works, or fails miserably.

For all the legal bits, I’m not at all affiliated with Amazon or Sozu – so please use at your own risk :)

GalleryTweet – Twitter for your Gallery2

Saturday, April 25th, 2009

This post is no longer being maintained due to budget constraints - please check the project page for the latest information: http://codex.gallery2.org/Gallery2:Modules:gallerytweet

I’m releasing the updated module for Gallery2 under the name of GalleryTweet. It was prompted by a few people mentioning they couldn’t get my earlier hack to work – so I thought I’d build something that was (slightly) more robust, and might stand to work on installations other than my own.

You might want to skip my ramblings and jump straight to the download, so here’s a link for you folks:

  1. Install by unzipping to the root of your Gallery2 installation, and activate through the plugins panel.activate
  2. Once logged in, edit your Twitter settings through the left navigationmenu
  3. You should enter your twitter username / password, and the format you’d like to send your Tweets out with.twitter-settings
  4. Now while you’re browsing the Gallery, Tweet about any images using the link below the thumbnailtweet

Please drop me a message on Twitter @kevinblake if you’ve found the plugin useful, can’t get it work, or have any other feedback.  That download link again, in case you missed it the first time:

Happy Tweeting!

This post is no longer being maintained due to budget constraints - please check the project page for the latest information: http://codex.gallery2.org/Gallery2:Modules:gallerytweet

Twitter your Gallery 2

Sunday, February 15th, 2009

Seems everyone is talking about Twitter nowadays.  The Hudson River picture launched it into the media world as the best news source on the planet, and Obama‘s adoption of the tool has given America the same pleasure that Britain experienced when our Prime Minister, Stephen Fry starting getting ‘back in touch with the people’, in October 2008.

The Hudson River picture wouldn’t have been possible without the non-affiliated TwitPic – which never truly got the recognition it deserved.  Without it, the infamous picture would have only been a 140 character description, and nobody will have noticed or cared.  Still, that’s the nature of buzzwords I guess.  If they don’t cause a buzz, they’re just words.

Anyway, TwitPic is yet another disparate service like Flickr, Panoramio or Facebook that’s had me tempted away from uploading some of my photos to Gallery2 / Blakepics.  With Facebook, I’ve integrated my own application there; Panoramio and Flickr, stolen the best parts of each.

And now with a hack to the tagging module in Gallery 2 I can emulate all I want from TwitPic as well, and tuck another service onto the shelf at the back at the cupboard.  So as usual, I thought I’d share.

What it is…

  • Tweet any photos on Gallery just by adding the tag ‘twitter’ to your photo.
  • Automatically takes the photos title as your Tweet text.
  • Processes all URLs through TinyURL, giving you a warm and fuzzy Tiny URL

What it isn’t…

  • A seamless Gallery2 module.  There’s some hacking to do.
  • Multi-user.  If you share your Gallery, there’s some more work to do.

If you make improvements in these areas or any others – please let me know :)

Requirements

Things you need to do

  1. Download my Twitter Tags class
  2. Unzip to the root of your Gallery installation
  3. Edit /modules/tags/classes/TwitterTag.class with your twitter username/pass, and Gallery URL.
  4. Edit /modules/tags/classes/TagsHelper.class
    1. Add this just above the line ‘class TagsHelper’
      GalleryCoreApi::requireOnce('modules/tags/classes/TwitterTag.class');
    2. Then just above
      return TagsHelper::assignTagById($itemId, $tagId);
      Add
      TwitterTag::Tweet($itemId, $tagId);
  5. Tag any photos you want to appear on Twitter with ‘twitter’.