List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory(String configTreePath)
From source file:demo.UserInfo.java
License:Apache License
public static void main(String[] args) throws IOException, TwitterException { //?//from w w w. ja va2 s . co m Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build(); Twitter tw = new TwitterFactory(configuration).getInstance(); String screenName = ""; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("????ScreenName???????!! ex)masason : "); screenName = br.readLine(); //String screenName = "masason";//masason try { //?& User user = tw.showUser(screenName); System.out.println("???"); System.out.println("User ID : " + user.getId()); System.out.println("ScreenName : " + user.getScreenName()); System.out.println("User's Name : " + user.getName()); System.out.println("Number of Followers : " + user.getFollowersCount()); System.out.println("Number of Friends : " + user.getFriendsCount()); System.out.println("Language : " + user.getLang()); //? Status status = user.getStatus(); System.out.println("???"); System.out.println("User Created : " + status.getCreatedAt()); System.out.println("Status ID : " + status.getId()); System.out.println(status.getSource()); System.out.println("Tweet" + status.getText()); } catch (Exception e) { e.printStackTrace(); } }
From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java
/** * Configures Twitter API Keys/*from w w w .j av a2 s . c o m*/ */ public static void config() { if (tf == null) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true) .setOAuthConsumerKey(Props.getOrDefault("OAuthConsumerKey", "8MEY2XDvYPblVVQgFdSzSrydQ")) .setOAuthConsumerSecret(Props.getOrDefault("OAuthConsumerSecret", "IpKkXw2gvfJCEwjGv2Yz5LwRv0Zn1B9nMLkQVleldyhdVPgPVj")) .setOAuthAccessToken(Props.getOrDefault("OAuthAccessToken", "2646251996-E0Glh4yG12AyJ6DM7PCy9sTKhs0w8gP4yCFFvU2")) .setOAuthAccessTokenSecret(Props.getOrDefault("OAuthAccessTokenSecret", "8D4sZcF8trluR1dFhqxhVoaf0xsrwTvwX93qkIbKFFxKP")); tf = new TwitterFactory(cb.build()); } }
From source file:edu.allegheny.gatortweet.GetHomeTimeline.java
License:Apache License
public static void main(String[] args) { try {/*from w w w . ja v a 2 s. co m*/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("rPtRCCRqdDyoxHS3E2UARA") .setOAuthConsumerSecret("hhDnR4NETStvN4F84km2xuBy3eXJ8l2FnjdL23YPs"); // gets Twitter instance with default credentials TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); /* Twitter twitter = new TwitterFactory().getInstance(); */ User user = twitter.verifyCredentials(); List<Status> statuses = twitter.getHomeTimeline(); //System.out.println("Showing @" + user.getScreenName() + "'s home timeline."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:edu.american.student.util.TwitterSpider.java
License:Open Source License
/** * Grabs the last 100 tweet objects (Status) from a handle * @param handle//from w ww .j av a 2 s.c o m * @return * @throws SpiderException */ public static List<Status> spider(String handle) throws SpiderException { //connect to Twitter ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(Constants.getTwitterOAuthConsumerKey()) .setOAuthConsumerSecret(Constants.getTwitterOAuthConsumerSecret()) .setOAuthAccessToken(Constants.getTwitterOAuthAccessToken()) .setOAuthAccessTokenSecret(Constants.getTwitterOAuthAccessTokenSecret()); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); //get tweets Query query = new Query("from:" + handle.replace("@", "")); query.setCount(100); QueryResult result; try { result = twitter.search(query); List<Status> toReturn = result.getTweets(); return toReturn; } catch (TwitterException e) { String gripe = "Twitter spider failed to...err spider!"; throw new SpiderException(gripe, e); } }
From source file:edu.mum.cs.wap.TwitterUtil.java
private static Twitter getTwitter() { if (twitter == null) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("ZhsCVnhHjs54ZLCxgE82n6GEa") .setOAuthConsumerSecret("FixRe4imh376SRWcxgoF14GdyaQjW7tLHE13mxcgNXNiObwSnr") .setOAuthAccessToken("935445715-EcVDaqqw7QQgcviXSOWWDT5ZCT8LkHbBNP1Pzd1W") .setOAuthAccessTokenSecret("PJIEzaRZB21tZP01CAaZEoEaVEcVvIRK6jMOlDyqc0peL"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();// ww w .j av a2 s .c om } return twitter; }
From source file:edu.proyectofinal.integradorrs.services.tweets.impl.TweetsServiceImpl.java
@Override public Collection<Status> getAllTweets(String email) { TwitterCredentials tc = TwitterCredentials.getInstance(); ConfigurationBuilder cb = tc.GetCredentials(email); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();//from w w w . j a v a 2s.co m List<Status> statuses = null; try { statuses = twitter.getHomeTimeline(); } catch (TwitterException ex) { Logger.getLogger(TweetsServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } Collection<Status> result = (Collection<Status>) statuses; return result; }
From source file:edu.proyectofinal.integradorrs.services.tweets.impl.TweetsServiceImpl.java
@Override public Collection<Status> getUserTimeline(String user, String email) { TwitterCredentials tc = TwitterCredentials.getInstance(); ConfigurationBuilder cb = tc.GetCredentials(email); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();/*w w w . j av a2s .c o m*/ List<Status> statuses = null; Paging paging = new Paging(1, 30); try { statuses = twitter.getUserTimeline(user, paging); } catch (TwitterException ex) { Logger.getLogger(TweetsServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } Collection<Status> result = (Collection<Status>) statuses; return result; }
From source file:edu.smc.mediacommons.panels.TwitterPanel.java
License:Open Source License
public TwitterPanel() { setLayout(null);/*from www .j a v a2 s . co m*/ jButton = Utils.createButton("Login", 210, 100, 100, 20, null); add(jButton); passwordField = new JPasswordField(); passwordField.setBounds(110, 100, 100, 20); add(passwordField); message = Utils.createLabel("Sign-in to Authenticate API calls", 80, 70, 300, 20, Resources.VERDANA_14_BOLD); add(message); // You can use your own credentials, and choose to encrypt them or not /* String tempEncrypted = null; try { InputStream inputStream = Main.class.getClassLoader().getResourceAsStream("YOUR_PATH"); InputStreamReader streamReader = new InputStreamReader(inputStream, "UTF-8"); BufferedReader reader = new BufferedReader(streamReader); tempEncrypted = reader.readLine(); } catch (IOException e) { }*/ final String encrypted = null; jButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); textEncryptor.setPassword(passwordField.getText()); String[] decrypted = textEncryptor.decrypt(encrypted).split("\\$"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(decrypted[0]).setOAuthConsumerSecret(decrypted[1]) .setOAuthAccessToken(decrypted[2]).setOAuthAccessTokenSecret(decrypted[3]); TwitterFactory tf = new TwitterFactory(cb.build()); twitterModule = new TwitterModule(tf.getInstance()); } catch (Exception ex) { JOptionPane.showMessageDialog(getParent(), "The input password was not correct."); return; } JOptionPane.showMessageDialog(getParent(), "Authentication successful."); restructurePanel(); } }); }
From source file:edu.uci.ics.asterix.external.util.TwitterUtil.java
License:Apache License
public static Twitter getTwitterService(Map<String, String> configuration) { ConfigurationBuilder cb = getAuthConfiguration(configuration); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();//from w ww . java 2 s. c o m return twitter; }
From source file:edu.umich.cse.pyongjoo.twittercrawl.GetUserTimeline.java
License:Apache License
/** * Usage: java twitter4j.examples.timeline.GetUserTimeline * * @param args String[]/*from w w w . j av a 2 s . com*/ * @throws IOException */ public static void main(String[] args) throws IOException { OAuthTokenReader oauth = new OAuthTokenReader("oauth_tokens.csv"); TwitterFactory tf = new TwitterFactory(oauth.getNextConfiguration()); // gets Twitter instance with default credentials Twitter twitter = tf.getInstance(); if (args.length < 2) { System.err.println("Usuage: command [username] [outputfile]"); System.exit(-1); } String filename = args[1]; FileWriter fstream = new FileWriter(filename, true); BufferedWriter out = new BufferedWriter(fstream); String user = ""; if (args.length >= 1) { user = args[0]; } // out.write("#document starts with username: " + user + "\n"); for (int i = 1; i <= 1; i++) { Paging pagingOption = new Paging(i, 200); try { List<Status> statuses; statuses = twitter.getUserTimeline(user, pagingOption); System.out.println("My Custom Showing @" + user + "'s user timeline."); for (Status status : statuses) { out.write(status.toString() + '\n'); System.out.println(status.getUser().getScreenName() + "tweets written."); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); // close the file out.close(); // output.close(); System.exit(-1); } } // close the file out.close(); // output.close(); }