First I looked at available Twitter libraries for Java:
After some considerations, I chose Twitter4J. To me, it seemed to be the most active of the three projects. Even better, it has a BSD-style license. Using Twitter4J is super simple:
Twitter twitter = new Twitter("username", "password");
try {
twitter.updateStatus("My tweet");
} catch (TwitterException e) {
…
}
There is so much more you can with Twitter4J. Check out its documentation for further details.
Secondly, as each tweet contains a link back to the job detail page in the main application, I was looking into ways to shorten URLs. That way, I can store more job posting related data within the only 140 characters available for each Twitter status update.
The original service for this is TinyURL. However, it looks like bit.ly has more traction these days and is also used directly by Twitter itself. The nice thing about bit.ly is that they have developer accounts and are offering a web service API for doing URL shortening.
Even better, there is already a Java library available for using bit.ly called bitlyj. Using bitlyj is actually almost as equally simple to use as Twitter4j:
final Bitly bitly =
BitlyFactory.newInstance("username", "your_bitly_api_key");
try {
BitlyUrl bUrl = bitly.shorten("http://www.google.com/");
URL url = bUrl.getShortUrl();
} catch (IOException e) {
…
}
Unfortunately, you have to build bitlyj yourself, but thanks to Maven it is a piece of cake. One thing I noticed, is that the error handling of the library could be more robust. Accidentally, I was using my bit.ly password, initially. However, bit.ly provides an API Key. By the way if you ever wonder where you can get that API Key-It is right in your account page. Anyway, the library needs some attention but for my simple use-case it worked fine.