Adding URL shortner to B2evo twitterlution plugin

12/22/09

Permalink 09:30:55 pm, by dave Email , 268 words, 6825 views   English (US)
Categories: Web Technologies

Adding URL shortner to B2evo twitterlution plugin

I finally got around to adding the twitterlution plugin from Lee Turner and it works great. One thing I noticed was the long URLs from my blog being sent to twitter. Other than that, I am extremely happy with the plugin.

I wondered how hard it would be to add a URL shortener (bit.ly in this case) to the plugin. It turned out to be fairly straight forward.

First I went and got a userid and apikey to bit.ly

Then I searched for an example of making a call to bit.ly from php and I found this example by James Cridland

Then I added the Services_JSON module to my web server

[More:]

Then I knitted it all together - see the code snippets for the pertinent parts.

First I added a reference to the Services_JSON module in the plugin php file.

Then I added the following to the GetDefaultUserSettings function:

PHP:

'bitly_userid' => array(
      'label' => T_'Your bit.ly Userid' ),
),
'bitly_apikey' => array(
      'label' => T_'Your bit.ly api key' ),
      'type' => 'password',
),

Then I added the function from James Cridland's example, with the following modification:

PHP:

$bitly_login $this->UserSettings->get'bitly_userid' );
$bitly_apikey $this->UserSettings->get'bitly_apikey' );

Finally, I changed the ItemSendPing function with this one line modification (where the new function to shorten the URL was called):

PHP:

$perm_url $this->get_short_link($params['Item']->get_permanent_url());

Thanks to Lee Turner for a great plugin and to James Cridland for giving us an easy way to call bit.ly.

Cheers,
Dave



Did you like this post? If so, Share it!  del.icio.us digg reddit slashdot this article Facebook Twitter MySpace Email



Pingbacks:

No Pingbacks for this post yet...

This post has 12 feedbacks awaiting moderation...

Scripts

This is somewhere I can post interesting snippets as I come across them. Hopefully some folks out there will find this helpful.

Search

Follow Me:

Misc

Who's Online?

  • Guest Users: 1

powered by b2evolution free blog software