Bit.ly API command line tool

I’ve knocked up a really simple command line tool for interacting with the bit.ly API.

It’s simple because:

  1. The output is currently pretty raw
  2. The bit.ly API doesn’t actually do very much

ยป Download version 0.1.1

Requires PHP >= 5.2.x + json extension

INSTALL

Ensure you have a PHP binary at /usr/bin/php and check the version is suitable

$ which php
/usr/bin/php
$ /usr/bin/php --version
PHP 5.2.x (cli) (built: ..........)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

Unzip the download, and ensure it’s executable:

$ tar -xvzf bitly-0-1-1.tar.gz
bitly-0-1-1/
bitly-0-1-1/bitly
bitly-0-1-1/README
$ cd bitly-0-1-1
$ chmod u+x bitly

Configure it for your bit.ly account, by redefining two constants at the top of the file. They look like this:

define( 'BITLY_USER', '' );
define( 'BITLY_PASSWORD', '' );

Optionally move the executable somewhere useful:

$ mkdir -p ~/bin
$ mv -v bitly ~/bin
bitly ->/home/xxxx/bin/bitly

USAGE

Run the help command to see available commands

$ bitly -h

Example, to shorten a URL:

$ bitly shorten http://web.2point1.com

CHANGELOG

Version 0.1
First release

Version 0.1.1
Added –version switch
Added history=1 into shorten method (ensures it actually goes into your bit.ly history)
Added optional keyword for custom URLs to shorten method

See also

bit.ly API documentation

  1. February 2nd, 2010 at 21:04 | #1

    Great! Thanks! :)

  2. Patagon
    March 8th, 2010 at 21:08 | #2

    It seems to work, but if you want to use it in a shell script how do you pass the short_url to a shell variable?

    Thanks

  1. No trackbacks yet.