ic: website ic:blog
  ic: website Home · Archives · Photo Gallery · ic: forum RSS logo - thanks to www.nineteenlabs.comWeb feed (RSS)  
The life and times of james Hart: his family, his music, life in Luton and his occasional escapes onto the internet.

« Google Maps over 3G / GSM on the i600 (techie) | Main | Weekend away »

Friday, 3 April 2009

Can I get the MT-Twitter plugin to use TinyURL?

This evening, I've had a bit of trouble getting my blog entries to appear as sensible URLs on Twitter. For some reason, the clever API that used automatically to send the web link to the ever-useful TinyURL.com seems to have stopped working, leaving a half-finished URL which - frankly - doesn't work.

As I mentioned in a blog post over a year ago, I've been using the MT-Twitter plug in from Chopstix Media, which is a clever Perl script that posts the entry to Twitter.

I thought I'd make a slight modification to twitter.pl, based on a useful post by James Januszka. I took:

.
.
require LWP::UserAgent;
my $intro = 'Published a new blog post: ';
if ($config->{twitter_intro}) { $intro = $config->{twitter_intro}; }
my $text = $intro . $entry->title . ' ' . $obj->permalink;
my $ua = LWP::UserAgent->new;
.
.

and replaced it with:

.
.
require LWP::UserAgent;
my $intro = 'Published a new blog post: ';
if ($config->{twitter_intro}) { $intro = $config->{twitter_intro}; }
my $posturl = $obj->permalink;
my $url = 'http://tinyurl.com/api-create.php?url='.$posturl;
my $browser = LWP::UserAgent->new;
my $response = $browser->get($url);
my $tinyurl = $response->content;
my $text = $intro . $entry->title . ' ' . $tinyurl;

my $ua = LWP::UserAgent->new;
.
.

The theory's sound.. this, however, will test whether or not it works. A crash-course in Perl if ever I needed one..!

[edit]Hooray - it works![/edit]

Posted by james at April 3, 2009 10:37 PM


 
This site is owned and operated by Image Communications, including all content and stuff.
It's powered by Movable Type 5.2