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

  3. March 18th, 2011 at 16:50 | #3

    Doesn’t work for me. Can you post a public source repo (github?) so I can send you a patch?

    Even after adding my auth at the top, I get the error:

    Array
    (
    [errorCode] => 500
    [errorMessage] => MISSING_ARG_LOGIN
    [results] =>
    [statusCode] =>
    )

  4. August 16th, 2011 at 02:45 | #4

    I get the same error

    Ralph Bean :
    Doesn’t work for me. Can you post a public source repo (github?) so I can send you a patch?
    Even after adding my auth at the top, I get the error:
    Array
    (
    [errorCode] => 500
    [errorMessage] => MISSING_ARG_LOGIN
    [results] =>
    [statusCode] =>
    )

  5. tim
    September 16th, 2011 at 12:59 | #5

    Guys, as you can see this little project is two years old and not maintained.
    I shall try to find some time to fix, and will add to Github.

  6. November 15th, 2011 at 04:51 | #6

    @tim
    Definitely! It’s a great little thing, it would be cool to have it working and maintained :)

  7. November 15th, 2011 at 04:52 | #7

    tim :
    Guys, as you can see this little project is two years old and not maintained.
    I shall try to find some time to fix, and will add to Github.

    Definitely! It’s a great little tool, would be cool to have it working and maintained! :)

  1. No trackbacks yet.