Alberto Embedded & Open experience

Notes on my experience on Open Source Embedded Systems

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!

Advertisements

Written by Alberto!

04/09/2010 at 10:26 am

Posted in linux

Tagged with , , ,

4 Responses

Subscribe to comments with RSS.

  1. Hi Alberto,

    Regarding the issue that there’s no key bundled with bti, please see my blog post: http://gluegadget.com/blog/index.php?/archives/34-Twitter,-OAuth-and-bti.html

    It’s mostly because twitter’s OAuth implementation.

    And thanks for the post 🙂

    Amir

    04/09/2010 at 5:27 pm

    • Well, thank you for the efforts to develop the OAuth support for bti!
      I decided to have a Twitter account only because there were the possibility to tweet by the shell and your efforts make this possible!

      Thank to you and to Greg Kroah Hartman for your mad but useful ideas 🙂

      Alberto!

      04/09/2010 at 5:37 pm

  2. Hi, I kept on getting the following error messages, while trying to compile LIBOAUTH:

    configure.ac:41: required file `../ltmain.sh’ not found

    No package ‘libcurl’ found

    And so on.

    Turned out we need to do the following first :

    sudo apt-get remove automake
    sudo apt-get install libcurl4-openssl-dev automake1.7

    Hope it helps !

    sufehmi

    10/12/2010 at 8:52 am

  3. To compile bti itself successfully, we’ll need to do the following first :

    sudo apt-get install libpcre3-dev

    By the way, I’m using Ubuntu Lucid / 10.04

    Hope it helps.

    sufehmi

    10/12/2010 at 8:56 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: