I’ve knocked up a really simple command line tool for interacting with the bit.ly API.
It’s simple because:
- The output is currently pretty raw
- The bit.ly API doesn’t actually do very much
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://timwhitlock.info
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