List of usage examples for twitter4j Twitter getUserTimeline
ResponseList<Status> getUserTimeline(String screenName) throws TwitterException;
From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java
License:Open Source License
public static ArrayList<Item> getFluxFromUser(String user, String sourceUri) { ArrayList<Item> result = new ArrayList<Item>(); try {// w w w .j a va 2 s . c o m Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(Config.getVar("Twitter-OAuth-customer"), Config.getVar("Twitter-OAuth-customerKey")); twitter.setOAuthAccessToken(new AccessToken(Config.getVar("Twitter-OAuth-access"), Config.getVar("Twitter-OAuth-accessKey"))); List<Status> statusess = twitter.getUserTimeline(user); for (Status r : statusess) { result.add(TwitterApi.getItemFromStatus(r, sourceUri)); } return result; } catch (TwitterException ex) { logger.warn(ex.getErrorMessage()); return result; } }
From source file:servlet.TwitterClient.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w .j a va 2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { String consumerKey = "acdi5Tpjda5dshPSgsNdc2YuP"; String consumerSecret = "5mZuFFShjXdwTCbk1hRZ9c47BJz9vKwoPFDPDHyG9xdxLGdZRi"; String accessToken = "224428346-hU7uwq12mUSvxT7jClIEnpCN5Lj6Rp1YgnQiwG6h"; String accessTokenSecret = "8kPqai6ciArmiWinkBOGvxHfYbif2OL7N96NbQYvEHfiH"; Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); AccessToken accessTok = new AccessToken(accessToken, accessTokenSecret); twitter.setOAuthAccessToken(accessTok); String action = (request.getParameter("action") != null) ? request.getParameter("action") : "fresh"; if (action.equalsIgnoreCase("Send")) { String latestStatus = request.getParameter("newTweet"); Status status = twitter.updateStatus(latestStatus); } //cargamos todos los tweets ResponseList<Status> a = twitter.getUserTimeline(new Paging(1, 20)); request.setAttribute("Tweets", a); //mandamos los tweets en una lista a la vista request.getRequestDispatcher("twitter.jsp").forward(request, response); }
From source file:traffickarmasent.newgetpage.java
public static void main(String[] args) throws IOException { // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); try {/*from www . j a va2s. c om*/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey("GPtsu5cjC08KTOEojEoaHw"); cb.setOAuthConsumerSecret("SsgeXn73bN4CXUYtJfEdKOwBxVTmAEPvmFo3q2CX45w"); cb.setOAuthAccessToken("154196958-J1Gqy86jmQ6YSoFVVq69bmbJB0acGxiDEocxtvre"); cb.setOAuthAccessTokenSecret("DpTJr3huuDy2qMwsCMgsTn5yNbi0oQzSDGhDDWQsLog"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter1 = tf.getInstance(); List<Status> statuses; String user; String[] users = { "livetrafficsyd", "trafficnsw", "sydtraffic_cs", "WazeTrafficSYD", "livetrafficnsw" }; Date[] d_users = { new Date(99, 2, 12), new Date(99, 2, 12), new Date(99, 2, 12), new Date(99, 2, 12), new Date(99, 2, 12) }; while (true) { for (int i = 0; i < users.length; i++) { statuses = twitter1.getUserTimeline(users[i]); for (int j = statuses.size() - 1; j >= 0; j--) { Status st = statuses.get(j); if (d_users[i].before(st.getCreatedAt())) { String message = removeUrl(st.getText()); File file = new File("out_sydney_new.txt"); //if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } //true = append file FileWriter fileWritter = new FileWriter(file.getName(), true); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); bufferWritter.write(message + "\n"); bufferWritter.close(); System.out.println("Done"); System.out.println("@" + st.getUser().getScreenName() + " - " + st.getText()); d_users[i] = st.getCreatedAt(); } } } try { Thread.sleep(300000); //1000 milliseconds is one second. } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("firse"); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:tweete.Tweete.java
License:Open Source License
public void showTimeline() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("######################") .setOAuthConsumerSecret("######################") .setOAuthAccessToken("############################################") .setOAuthAccessTokenSecret("############################################"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try {/*from w w w . ja v a2 s . c o m*/ ResponseList<Status> a = twitter.getUserTimeline(new Paging(1, 10)); String statuses = ""; for (Status b : a) { statuses = statuses + b.getText() + "\n\n---------------------------------------\n\n"; } new TweeteTimeline().Timeline(statuses); } catch (TwitterException te) { //te.printStackTrace(); if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else if (92 == te.getStatusCode()) { System.out.println("SSL is required"); } else { System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } } catch (Exception e) { System.out.println("Something went wrong"); } }
From source file:twitter.TweetGet.java
public void getTweetFromUser(String username) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("2MZnm7LM7Ik9W3hzcXJOBaNER") .setOAuthConsumerSecret("0GER2kH3o1gOAyfPEDd870Iiuiu6XbQDayAXWfUBxU5APg4Le6") .setOAuthAccessToken("18972247-HgBP0djVaLw4U9fSX4lUdhKpZcqsJIAgnUCW3DRS5") .setOAuthAccessTokenSecret("bn8EQoOyGSRVUNX6elTmX9Wt9jiFJaxDaCZDk3U3hQB0g"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); try {/* ww w. ja va 2s . co m*/ tweets = twitter.getUserTimeline(username); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); } }
From source file:twitter4j.examples.timeline.GetUserTimeline.java
License:Apache License
/** * Usage: java twitter4j.examples.timeline.GetUserTimeline * * @param args String[]/* w w w. ja v a2 s . com*/ */ public static void main(String[] args) { // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); try { List<Status> statuses; String user; if (args.length == 1) { user = args[0]; statuses = twitter.getUserTimeline(user); } else { user = twitter.verifyCredentials().getScreenName(); statuses = twitter.getUserTimeline(); } System.out.println("Showing @" + user + "'s user 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:twitterrest.Timeline.java
License:Apache License
public static void main(String[] args) throws TwitterException { Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build(); Twitter tw = new TwitterFactory(configuration).getInstance(); List<Status> list = tw.getUserTimeline("masason");//ScreenName[anondroid5] for (Status status : list) { System.out.print(status.getCreatedAt() + " ");//CreatedDate System.out.print(status.getUser().getScreenName() + " ");//ScreenName System.out.println(status.getText());//tweet }/*from w ww. jav a 2 s. c o m*/ }
From source file:utils.GetTwitters.java
License:Open Source License
public Iterable<MessageTwitter> getMessages() { List<MessageTwitter> messages = new ArrayList<MessageTwitter>(20); if (LastUpdate.getInstance(compte).isUpdate()) { LOGGER.fine("Les messages twitter sont jour, envoie du contenu de la base de donne"); messages.addAll(MessageTwitter.findByCompte(compte)); } else {// w w w .jav a 2s .c om LOGGER.fine("Les messages twitter ne sont pas jour, rcupration du contenu de twiter"); Twitter twitter = getFactory().getInstance(); twitter.setOAuthConsumer("9Jsib4k1uEMCWZqEHy1t1Q", "vLQQaog60gYRrPCC2bHeEZdod3JDSkTRI9W7r2cZIZ8"); twitter.setOAuthAccessToken(new AccessToken("225864007-Y11ZtDLq2LVZwMR3anKxPW9nR6dIGkLyFlOhdAMx", "GQ16L9QMhhzSiRT4xRia7B25011BoNsXUEgUyp0vKI")); ResponseList<Status> listeStatus; try { listeStatus = twitter.getUserTimeline("@" + compte); } catch (TwitterException e) { LOGGER.log(Level.SEVERE, "Erreur lors de l'accs twitter", e); return MessageTwitter.findByCompte(compte); } for (Status status : listeStatus) { messages.add(new MessageTwitter(status.getCreatedAt(), status.getText(), compte)); } MessageTwitter.deleteAll(); for (MessageTwitter message : messages) { message.save(); } } Collections.sort(messages, new Comparator<MessageTwitter>() { public int compare(MessageTwitter o1, MessageTwitter o2) { return o2.getDateCreation().compareTo(o1.getDateCreation()); } }); return messages; }