Home / Blog / Howto Tweet and Still Get Stuff Done

Howto Tweet and Still Get Stuff Done

Tweets are the original Web answer to "What are you doing right now?".

Besides an amusing diversion for the self-absorbed, they can be a wonderful time tracker for those trying to get stuff done.

When watching the return value, the instant Web publishing hit can be more than a little addictive. It can become an end unto itself, even a business, think Guy Kawasaki and alltop.com.

Working at the command line interface (cli), keeps it clean and fast to keep your day moving without cognizant interruption. Think, and thank, Binny VA. binnyva.blogspot.com

Happy muddling along for 3 plus years with a fast clean curl implementation came to an end September 2010. Twitter no longer allows the --basic authentication that made that possible. It once was one line, broken into three here for clear display.

curl --basic --user "name:password" --data-ascii 
"status=`echo $@|tr ' ' '+'`" 
"http://twitter.com/statuses/update.json" 

Saved as "tw" in a location on the users PATH, call it from cli passing the tweet as the only necessary parameter, like this:

tweet from cli

tweeting from the command line

Difficult to imagine a cleaner more straightforward mechanism for cli types to tweet.

oauth

The new way to authenticate, oauth, is better for twitter. Will surely be better for all twitter users in the long run. But it breaks anything that still depends on --basic authentication. Like the simple one line script above.

Twitter has apparently been warning developers for months. Those of us just running simple hacks were caught unaware on September 02, 2010, when basic authentication just stopped working.

The Fix

I know most will thrill to the intricacies of oauth as much as me. Don't know, don't care, just tell me something that will fix what is broken.

What You Need - Registration Required

Four essential pieces of information and a small library to handle the oauth connection.

The consumer key and consumer secret are provided by twitter when the developer registers an app with them. Anybody accessing the twitter api is now forced to be a registered developer. Better for advance notifications for sure!

The name of this app registered with twitter is wpm-tw-api-localtracker. The app name displays as the source any time status messages are sent to the twitter servers and displayed online. My pet name for the app when it was a command line script was twittertracker, because it saved a copy to a local database for quick future reference to every tweet ever made. So much for history, on with the details.

Raj Deut article on sitepoint explains getting those four pieces of information and the oauth libraries better than I could ever hope to.

  • consumer_key
  • consumer_secret
  • accessToken
  • accessTokenSecret

The accessToken and accessTokenSecret are specific to each user. Each user must already have a twitter account.

So two items per app, two items per user, then ready to oauthenticate using two files, the bottom two in the image below, in what is called the twitteroauth library by Abraham Williams available here.. There is a lot more stuff in the download, but those two files are the essence.

twitter oauth library

twitter oauth library

All that remains is to make the oauth call into the library with the 4 crucial pieces of information, then when authenticated, send the tweet.

Authenticated=Good, verify user name, if that checks out, send a tweet, a "status" update in twitter api terms.

-----twittersaver.php file for testing------------------------

require_once("abraham/twitteroauth/twitteroauth.php");

$oauth = new TwitterOAuth(consumer_key, consumer_secret, accessToken, accessTokenSecret);

$credentials = $oauth->get("account/verify_credentials");

echo "Connected as @" . $credentials->screen_name;

$oauth->post('statuses/update', array('status' => "Thanks Raj Deut Sitepoint, very nicely done."));?>

-----------------------------------------------------

When this is working, remove the "echo" line and switch 'status' => "Thanks Raj Deut Sitepoint, very nicely done.", to 'status' => $_REQUEST[status]

Then make a curl call from cli to script tw, the text entered will fill in a the echo location, and ultimately the _REQUEST[status]

 curl --data-ascii "status=`echo $@|tr ' ' '+'`"
 "http://localhost/twittersaver.php"