Last active
October 4, 2015 15:10
-
-
Save gansai/62bda8909f4d35ec4de2 to your computer and use it in GitHub Desktop.
Illustration on how to retrieve home timeline from twitter using 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(); | |
try { | |
List<Status> timeLineStatusList = twitter.getHomeTimeline(); | |
if(timeLineStatusList!=null && timeLineStatusList.size() >0) | |
{ | |
for(Status s: timeLineStatusList) | |
{ | |
System.out.println(s.getUser().getName() + " = "+ s.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