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.
2 comments:
If you have a specific scenario demonstrating how error handling in bitlyj could be more robust, please file an issue at the project site. I also implemented only the parts of the API that were useful to me, but if there's a specific piece missing that you'd like, file an issue for that too. I don't give the library enough time to even call it a side project, but I do address issues when raised. Thanks for the write up!
chris
PS If you know Gabriel Claramunt of the Atlanta Scala group, tell him Chris (burningodzilla on twitter) says hello!
Post a Comment