How To Integrate Your Custom Bit.ly API With Tweet This Plugin

Fri, Jan 22, 2010

Tutorials & Tips

Tweet This is a great plugin that allows you to have “Tweet This” buttons at the end of every post. Not only that, it also allows you to have Digg This, Facebook This, Plurk This, and many other kinds of buttons too. You get about 8 button designs as well, so you can find something that you like.

In addition to that, I like this Twitter plugin for its ability to tweet my posts automatically too, whenever I publish new posts on my blog. And the plugin is smart enough to integrate with various other URL shortening services!

My favourite URL shortening service is bit.ly, because they also have a great statistics and analysis tool. The problem is, Tweet This only creates generic bit.ly links – in order to use the statistics tool, you’ll need to connect with your own bit.ly API account.

I couldn’t find this feature supported by Tweet This, so I decided to hack it myself. To do this, just go to your Tweet This plugin folder, and edit the tweet-this.php file that you see inside.

Look for this line, or go to line 359:

$url = tt_read_file(‘http://bit.ly/api?url=’ . $purl);

and replace it with this chunk of code. Remember to change it to your details!

$bitlyLogin = ‘your-login-here’;
$bitlyAPIKey= ‘your-api-key-here’;

$url = tt_read_file(“http://api.bit.ly/shorten?version=2.0.1&longUrl=”.$purl.”&login=”.$bitlyLogin.”&apiKey=”.$bitlyAPIkey);

$response = @json_decode($url, true);
$url = $response['results'][$purl]['shortUrl'];

And that’s it!

You can get your bit.ly API key here.

Similar Posts:

Share and Enjoy!

Find this information useful or entertaining? Share it to the rest of the world!
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
  • FriendFeed
  • Reddit
, , , , , , , , , , , , , , , , , , , , , , ,

This post was written by:

Alvin - Alvin is a Singaporean who's interested in marketing, techy stuff and likes to just figure out how the two can work with each other. On top of his blog, you can also follow him on Twitter.

Get Alvin's Report On How To Blog Successfully - Free!

blog comments powered by Disqus