Created
October 3, 2015 11:49
-
-
Save gansai/345cfee301afc7ea1535 to your computer and use it in GitHub Desktop.
Post a Tweet from Java code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import twitter4j.Status; | |
import twitter4j.Twitter; | |
import twitter4j.TwitterException; | |
import twitter4j.TwitterFactory; | |
import twitter4j.conf.ConfigurationBuilder; | |
public class TweetMain { | |
public static void main(String[] args) { | |
ConfigurationBuilder cb = new ConfigurationBuilder(); | |
cb.setDebugEnabled(true) | |
.setOAuthConsumerKey("Key") | |
.setOAuthConsumerSecret("secret") | |
.setOAuthAccessToken("token") | |
.setOAuthAccessTokenSecret("tokensecret"); | |
TwitterFactory tf = new TwitterFactory(cb.build()); | |
Twitter twitter = tf.getInstance(); | |
Status status; | |
try { | |
status = twitter.updateStatus("First Tweet from within Java code @java,@twitter, @t4j_news"); | |
System.out.println("Successfully updated the status to [" + status.getText() + "]."); | |
} catch (TwitterException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment