Alberto Embedded & Open experience

Notes on my experience on Open Source Embedded Systems

Posts Tagged ‘twitter

Tweet from the linux shell on Ubuntu Karmic

with 4 comments

Twitter is something like a panel where you write all what you want in as short message style.

What makes Tweeter powerful (for me and for  IT developer) is the fact that nowadays IT companies look for job candidates also in these Social Networks. This is a way to find out the best candidates for a vacancy looking for already skilled people in what the vacancy involve.

Well, I am a kernel developer, so what is better than the ability to tweet my messages from bash???

This tutorial is for whom that want to do this also after the Tweeter strength of its authentication policy (now plain authentication is forbidden) with the OAuth mechanism.

The utility that can do this is called bti version 028 and upper, made by one of the most important member of the Linux development community: Greg Kroah Hartman.

Getting the source

So move into your preferred source directory, I will call it $BUILD and clone these repositories (it is needed a working installation of git and svn ):

$ cd $BUILD
$ git clone git://github.com/gregkh/bti.git
$ svn co https://oauth.googlecode.com/svn/code/c/liboauth

all other packages needed can be found with apt-get (or whatever other debian package management you like).

Compiling the source

First we have to compile liboauth (it is needed a working installation of automake and autoconf):

$ cd $BUILD/liboauth
$ mkdir m4
$ aclocal
$ automake --add-missing
$ autoreconf
$ ./configure
$ make
$ sudo make install

The library will be installed to /usr/local/lib, if you want another destination dir, change the –prefix as you want in configure time.

Now bti:

$ cd $BUILD/bti
$ ./autogen.sh
$ # Because of liboauth did not wrote the package configuration info:
$ ./configure LIBOAUTH_LIBS=/usr/local/lib/liboauth.a LIBOAUTH_CFLAGS="-g -O2"
$ make
$ sudo make install

In the configuration process you may be prompted to install other packages. You can find them with apt-get.

Make it work

Now you have the command bti available on your shell and you have to complete the OAuth authorization process to be able to post on your twitter account.

First create your configuration file as:

# comments are allowed in the bti config file
# rename this to ~/.bti so that you do not need
# to constantly enter your account name and/or
# password on the command line every time you send
# a message.
account="your account"
password="your password"
host=twitter
# Example of a custom laconica installation
#host=http://army.twit.tv/api/statuses
logfile=.bti.log
action=update
#user="your proxy user"
#proxy="http://your proxy address:port"
#shrink-urls=yes

and put it in ~/.bti.

Consumer key and secret

Now the “cloudy” part for me. Because consumer key and secret should be application specific as I understood so these keys  should be part of the bti application (correct me otherwise).

@update from Amir: Read this post to understand why those informations are not part of the bti sources http://gluegadget.com/blog/index.php?/archives/34-Twitter,-OAuth-and-bti.html.

Anyway you can register a new application to have access at your twitter following this link: https://twitter.com/apps/new. Please give the correct info on bti website as linked from this post but choose a different application name because bti is already choosen.

The application type is client without callback, must to have write permission and do not use twitter for the authentication.

Twitter will give you the two keys you need and You will put these at the and of your .bti config file as:

consumer_key=ambarabaciccicocco
consumer_secret=trecivettesulcomò

Then try your first run:

$ bti

You will be prompted to browse a specific link and past back the pin you see. Then you will be asked to add other two rows in your configuration file and  when you have done it, well all the process is completed! with the command:

$ echo "tweet what you want" | bti

You will be able to tweet all you want from the shell!

Enhancement

Maybe for someone lazy it is too much complicated the form with echo.

So I suggest to add the following lines at the end of your ~/.bashrc:

# $ tweet "your message"
function tweet {
 if [ ! "$*" ]; then
   echo 'Nothing to tweet!'
   return 1
 fi
 echo "$*" | bti
}

The comment on top explain how to use this function from the bash shell.

Hope you enjoyed this tutorial and please, any corrections or suggestions are welcome!

Alberto!

Written by Alberto!

04/09/2010 at 10:26 am

Posted in linux

Tagged with , , ,