Welcome again.
We all know that Java is very rich programming language,here is the another example of that.
In this program you will know how to Tweet on Twitter using java.(If you are new to Java this tutorial is Sufficient for you).
Requirements:
1. JDK 1.6 or 1.7.
If not installed, download and install it.
Download JDK here.
2. Eclipse IDE.
If not installed, download and install it.
Download Eclipse here.
3. Basic knowledge of Java.
If do not have,learn basics.
Learn Basic Java here.
Let's start it.
Step 1: You required 4 things to post on Twitter™ using Java.
Copy/Save 'API key' and 'API secret' because they are from 4 required codes.
Step 2: Open Eclipse IDE click on "File>New>Java Project" and name your project.
Step 3: Download Twitter jar file here.
Download Twitter Jar.
Step 4: Buildpath jar file to your project "Right click on project>Build Path>Configure Build Path>Add External Jar".
Step 6: Now Code "TwitterMain.java".
import twitter4j.Twitter;
//(Note: Don't forget to add API keys,secrets,accessToken,TokenSecret at XXXXXXXXXXXXXX).
Step 7: Run it...
Congrats.....you've done....Tweet using Java™.
We all know that Java is very rich programming language,here is the another example of that.
In this program you will know how to Tweet on Twitter using java.(If you are new to Java this tutorial is Sufficient for you).
Requirements:
1. JDK 1.6 or 1.7.
If not installed, download and install it.
Download JDK here.
2. Eclipse IDE.
If not installed, download and install it.
Download Eclipse here.
3. Basic knowledge of Java.
If do not have,learn basics.
Learn Basic Java here.
(Note: Before starting this tutorial I am assuming that all requirements are fulfilled by you.)
Let's start it.
Step 1: You required 4 things to post on Twitter™ using Java.
- API Key- (Twitter API keys code)
- API Secret- (Twitter Consumer secret code)
- Access Token- (Twitter Access Token code)
- Access Token Secret- (Twitter Token secret code)
You will get them here.Click to get them.
- Login and Click on "Create New App"
- Add details as follows (leave callback URL blank)
- Click on "Create your Twitter application".
- In "Application Settings" Click on "modify app permissions".
- Select "Read, Write and Access direct messages" and Click on "Update Settings".
- Click on "manage API keys".
- Scroll down and Click on 'Create my access token'.
- Copy/Save 'Access token' and 'Access token secret'.
- Smile, half work is done.....:-), let's code now.....
- (Note: Before going to second step I am assuming that you have completed step 1 and you have four things....[i.e...API Key,API Secret,Access Token,Access Token Secret])...
Step 2: Open Eclipse IDE click on "File>New>Java Project" and name your project.
- Click on finish.
Step 3: Download Twitter jar file here.
Download Twitter Jar.
Step 4: Buildpath jar file to your project "Right click on project>Build Path>Configure Build Path>Add External Jar".
- Select jar file wherever it is.
Step 5: Create class,name it 'TwitterMain' (or whatever).
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
public class TwitterMain {
static String APIKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
static String APISecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
static String accessTokenStr = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
static String accessTokenSecretStr = "XxxxxxxxxxxxxxxxxXXXXXXXXXXX";
public static void main(String[] args) {
try {
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(APIKey, APISecret);
AccessToken accessToken = new AccessToken(accessTokenStr,
accessTokenSecretStr);
twitter.setOAuthAccessToken(accessToken);
twitter.updateStatus("#SimpleJavaPro #TweetUsingJava #java #Twitter4J http://simplejavapro.blogspot.in/2014/07/");
System.out.println("Successfully updated the status in Twitter.");
} catch (TwitterException e) {
e.printStackTrace();
}
}
}
//(Note: Don't forget to add API keys,secrets,accessToken,TokenSecret at XXXXXXXXXXXXXX).
Step 7: Run it...
Congrats.....you've done....Tweet using Java™.
![]() |
Download "TweetUsingJava" |
No comments:
Post a Comment