VOOZH about

URL: https://www.javacodegeeks.com/2012/03/twitter-api-on-your-java-application.html

โ‡ฑ Twitter API on your Java Application - Java Code Geeks


Ever wonder of attaching your tweets to your Java Applications? I searching for the best API out there for this and lucky for me, I found it!

http://twitter4j.org/

A Simple How To:
The first thing we need to do is to create an application within your twitter account, grant it access and generate authentication tokens (although, the consumer tokens will also work and it will be automatically generated upon creating the application).

1) Create an Application in your twitter account: Go To > Settings > Applications > Developers > โ€œhereโ€. You must login with your twitter account (or the account that you will use in your API).

2) Create your application: Enter required fields.

3) A consumer keys will be given to you. if youโ€™re only looking to read status updates, this is sufficient enough for your needs.

The Code:
For this example, Iโ€™m using Eclipse IDE.
1) Create a New Java Project and include the Twitter4j Library (download it here).
2) Create a class and check the code below:

Console Output:

And the Actual Twitter Feed:

Download the code :p

Enjoy!

Reference: Twitter API on your Java Application from our JCG partner Alvin Reyes at the Alvin โ€œJayโ€ Reyes Blog.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

๐Ÿ‘ Photo of Alvin Reyes
Alvin Reyes
March 29th, 2012Last Updated: October 21st, 2012
9 384 1 minute read
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

9 Comments
Oldest
Newest Most Voted
benedek fazekas
14 years ago

what about using spring social? http://www.springsource.org/features/social bit unmature but does the trick and not only for twitter

0
Reply
Sachin Bhat
12 years ago

Hello. I did exactly the way you explained but i am failing to get the tweets on my output window. It is getting terminated. And secondly how can get all the tweets and not the tweets by the user i am following.

0
Reply
Markus
12 years ago

Hi! I wonder, how consumer key and consumer secret are stored in a secure way, so it can be accessed by the application. Itโ€™s not possible to use some kind of relaying server.

0
Reply
roma
11 years ago

Hi! Iโ€™ve tried a lot of method but only your is working, thanks!

0
Reply
shashi ranjan
11 years ago

I just executed your code its working but my requirement is to allow a user to login through twitter credentials.
please suggest

0
Reply
Chucho
11 years ago

Duuuude! MANY THANKS! I spent the past few hours trying to figure out how to use t4jโ€ฆ you just made my day. Thank you!

0
Reply
sangeeta
10 years ago

Iโ€™m beginner in this field and I m using Twitter4j in Eclipse in order to get tweet data for a university project Iโ€™m doing and I have stumbled upon a problem. I have successfully created a Twitter Application and obtained the keys; I have included the โ€œtwitter4j-core-4.0.4.jarโ€ in the Project by created a lib folder and adding the JAR to it using โ€˜build pathโ€™ > โ€˜add external archivesโ€™ I have built the project and found no errors, however when I run the application as Java Application I get the following message in โ€˜Consoleโ€™; โ€ GetUserStatus [Java Application] C:\Program Files\Java\jre7\bin\javaw.exeโ€ Doesโ€ฆ Read more ยป

0
Reply
amit
10 years ago

point to jdk instead of jre

0
Reply
Danish
9 years ago

run:
BUILD SUCCESSFUL (total time: 9 seconds)

I have run it in netbeans 8.0.2
Where is the other output?
Please help

0
Reply
Back to top button
wpDiscuz