Sunday, 26 February 2012

BI Second Project - Twitter API programming

Hi All,
I hope every one is almost done with their first project execution plan and already Dr. Ram has asked us to start the second project planning, I am having a lot of expectation from this project as many skills will be put to test, one of the challenging test would be api programming in twitter.

This tutorial will provide how to integrate twitter api for your BI second project, I have spend almost 2 weeks on this, I don't want you folks to waste so much of time and get started right away.

Here are the steps to start with twitter api.

1 )download the twitter api twitter4j-core-2.2.5 from twitter twitter4j.org .

2 ) Search for the above api in the zip file, and place on your local machine.

3) Launch eclipse and right click on any project you want to import the twitter4j api and select build path --> configure build path. below is the screen shot.

4) Under the library tab click " Add External Jar files", and import the jar file you downloaded.

5) Under the project folder you can see the sub folder "Referenced Libraries"

Just check all the packages and classes are there. If they are you are good to go.

Now you need to access the twitter data with this api, but you need to have an key and a secret key.

1 ) Go to twitter.com

2) Scroll down and you will find a developer hyperlink, click and get your self registered.

3) Fill out the form and get your key and secret key.

4) use the below code to test the connection.

//replace by correct values
twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
AccessToken at=new AccessToken("[token]", "[token secret]");
twitter.setOAuthAccessToken(at);
try {
RateLimitStatus rls=twitter.getRateLimitStatus();
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

5) use any of the function and play now.

I hope this would help you in Second BI project.

Please don't share the code any where else.