Friday, June 5, 2009

Program Your Applications To "Tweet" Their Status Updates To A Private Account

Databases like Oracle and SQL Server can automatically notify the outside world when a wide variety of events occur. For example,
  • The number of patients in the the emergency room has reached its limit.
  • The number of widgets in inventory has dropped to the reorder point.
  • A long-running search has ended.
  • An X-ray or other file has been accessed by someone without authorization.

Typically, notification that such an event has occurred is generated by code contained within a database procedure.

But, database-centric applications aren’t the only kind that can programmatically generate events. For example, when a security breach, employee mishap or other emergency is detected by the code written in a Web application, notification, often via redundant channels, may be sent.

Traditionally, a text (e.g., via email server) or speech (e.g., via a speech server) message is generated. However, suddenly, tweeting (a short message sent by
Twitter) has become a popular option.

What is Twitter?

To understand the usefulness of an interface to Twitter, you need to know what Twitter is.

It's sort of like IM but without the expectation that any particular person will be there to answer. It's very public. If you start your day off with a "Hello, Mom", everyone who “follows” you (that is, who has configured their feed to include your messages) will see it. This capability is sometimes called “micro-blogging”.

However, for the scenario under discussion, you can configure Twitter to allow only the people (or person) you want to see your tweet – with or without the need to authenticate.

The Twitter API supports Basic Authentication. Basic authentication allows a user to pass in a user name/password associated with a URL. If you've ever tried to navigate to a Web site and it popped up a dialog and asked for a username and password, that site was probably protected by basic authentication. (Twitter has just recently started offering OAuth authentication.)

Messages on Twitter are called “tweets” and cannot be longer than 140 characters.

In general, the goal of Twitter for most people is to communicate and stay in touch with people you know, would like to know, or have interests in common. You follow people much like you would “friend” them on other social networks. The people you follow show up in your stream. People talk about whatever it is that's on their minds. Sometimes you'll see people replying to each other and at other times, they just want to share a thought. However, these uses are quite different from the use we’re considering here.

The Twitter API

To make calls to Twitter from a database, one needs a method for plugging into Twitter. Fortunately, Twitter provides an API for performing almost any interaction that you might wish for, including the ability to post a tweet.

The first thing to do is to set up a Twitter account for your messages. You may want to setup a special Twitter account for this purpose, rather than using your primary account.

A caveat: internet access from within a corporate firewall, especially from a database server, is an iffy proposition at best. Many places don’t allow it at all. Some do allow it via a proxy. The larger an organization, the less likely it is to allow internet access from a database server.

There are Twitter-supplied libraries for 13 programming languages:

  • C#/.NET
  • Java
  • ActionScript/Flash
  • PHP
  • Ruby
  • PL/SQL
  • JavaScript
  • C++
  • Python
  • Scala
  • Perl
  • Eiffel
  • Objective-C/Cocoa