Adding URL shortner to B2evo twitterlution plugin
12/22/09
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
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
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:
Categories
- All
- Web Technologies (2)
- PHP (1)
- Windows Scripting (37)
- Batch Scripts (13)
- Wsh Scripts (23)
Archives
- December 2009 (2)
- March 2009 (2)
- February 2009 (3)
- January 2009 (2)
- December 2008 (4)
- November 2008 (1)
- October 2008 (1)
- February 2008 (1)
- December 2007 (3)
- July 2007 (1)
- April 2007 (1)
- February 2007 (2)
- More...
Misc
Who's Online?
- Guest Users: 3




