BANGALORE, INDIA: The popularity of Twitter, Facebook or MySpace amongst Internet user has increased by many folds. Even several enterprises have started using these social networking platforms as a platform to interact with their customers.
Many of these offer open APIs which allow you to integrate your own application to their application platform. Twitter is one such popular social networking site, better known as a microblogging site. Twitter allows people to send a brief update (tweet), about what they are doing and that tweet is visible to their followers and friends. Twitter also offers an open application interface through which you can access Twitter from your own application.
About Twitter4J
Many enterprises use Twitter to send updates about their products and services. Using Twitter APIs, they can integrate their intranet portals to Twitter and post updates directly from there without going to the main Twitter website.
Twitter4J is a Java library for Twitter API. This readymade set of libraries allow you to query Twitter for various aspects. For instance, you can create a Java based web application that you can integrate with the organizations portal which will allow users to see the latest Twitter updates for their organization or company.
Twitter4J is completely implemented in Java and spares you the hassles of creating your own wrapper for Twitter APIs for your Java application to access Twitter. It allows all the functionalities for accessing Twitter, and is easy to use. Here, we will demonstrate how you can use Twiter4J to access Twitter through a Servlets Web application.
Getting Started
To start building your web application that will access Twitter, you need to download Twitter4J from the URL provided in the Direct-Hit box. The current version of Twitter4J is 2.0.8 which was released in mid June and has a bug fix over the previous version that used to give a NumberFormatException error while fetching user timelines from Twitter. Once you download Twitter4J package from the website, extract it into a folder, and in the extracted contents you can find the Twitter4J library along with documentation and examples. Using Twitter4J is simple. You just have to add the twitter4j-2.0.8.jar library to your application's classpath or into your project's refered libraries.
 |
|
While creating the project, choose the Target Runtime as the server on which you will run your project. To add a server follow the steps as shown in the visual.
|
Twitter4J requires Java platform version 1.4.2 or later. For this demonstration, we will create the web application in a development environment having Eclipse 3.4 with JDK 1.6 installed and using Tomcat 6.0 as the application server. The application which we'll create will be using Twitter4J to access Twitter to send an status update and will also fetch messages from the user's friends timeline.