Twitter API on your Java Application

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 two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

4 Responses to "Twitter API on your Java Application"

  1. benedek fazekas says:

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

  2. Sachin Bhat says:

    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.

  3. Markus says:

    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.

  4. roma says:

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

Leave a Reply


3 − three =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close