List of usage examples for twitter4j Status getCreatedAt
Date getCreatedAt();
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
public void write(Status t) throws XMLStreamException { startElement("tweet"); attribute("id", t.getId()); // write("annotations",t.getAnnotations()); write("created-at", t.getCreatedAt()); write("from-user", sanitizeID(t.getUser().getId()), sanitizeUser(t.getUser().getName())); write("geo-location", t.getGeoLocation()); write("hash-tags", t.getHashtagEntities()); write("iso-language-code", t.getUser().getLang()); write("location", t.getUser().getLocation()); write("media", t.getMediaEntities()); write("place", t.getPlace()); write("profile-image-url", sanitizeUser(t.getUser().getProfileImageURL())); write("source", t.getSource()); write("text", t.getText()); write("to-user", sanitizeID(t.getInReplyToUserId()), sanitizeUser(t.getInReplyToScreenName())); write("url-entities", t.getURLEntities()); write("user-mention-entities", t.getUserMentionEntities()); endElement();// w ww.j av a 2 s . co m }
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
public void write(String localName, Status status) throws XMLStreamException { if (status != null) { startElement(localName);/*ww w. ja v a 2 s .co m*/ attribute("id", status.getId()); // write("annotations",t.getAnnotations()); write("created-at", status.getCreatedAt()); write("user", status.getUser()); write("geo-location", status.getGeoLocation()); write("hash-tags", status.getHashtagEntities()); write("media", status.getMediaEntities()); write("place", status.getPlace()); write("source", status.getSource()); write("text", status.getText()); write("url-entities", status.getURLEntities()); write("user-mention-entities", status.getUserMentionEntities()); endElement(); } }
From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java
License:Open Source License
/** * create an item by his twitter Status description, will add hashtags and others "metas" * @param s the twitter Status/*from ww w. ja va 2 s . co m*/ * @param source the Uri of the source * @return the item created */ private static Item getItemFromStatus(Status s, String source) { String text = s.getText(); if (s.isRetweet()) { text = s.getRetweetedStatus().getText(); } Item res = new Item(source, "https://twitter.com/" + s.getUser().getScreenName() + "/status/" + Long.toString(s.getId()), text, text, s.getCreatedAt()); String[] hashtags = getHashTags(res.getDescription()); for (String hashtag : hashtags) { res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_HASHTAG, hashtag, true, true)); } for (String mentioned : TwitterApi.extractor.extractMentionedScreennames(s.getText())) { res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_MENTIONED, "@" + mentioned, true, true)); } if (s.getGeoLocation() != null) { res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LONGITUDE, Double.toString(s.getGeoLocation().getLongitude()), true, true)); res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LATITUDE, Double.toString(s.getGeoLocation().getLatitude()), true, true)); } res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_AUTHOR, "@" + s.getUser().getScreenName(), true, true)); return res; }
From source file:Origin.Mypage.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); /* TODO output your page here. You may use following sample code. */ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/*from w ww.j ava 2 s . com*/ cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User user = twitter.verifyCredentials(); request.setCharacterEncoding("UTF-8"); HttpSession hs = request.getSession(); UserData ud = (UserData) hs.getAttribute("ud"); String search = ud.getLine() + "?"; //String search= request.getParameter("searchtweet"); Query query = new Query(); query.setCount(100); query.setQuery(search); QueryResult queryresult = null; try { queryresult = twitter.search(query); } catch (TwitterException e1) { e1.printStackTrace(); } ArrayList<String> userID = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { userID.add(tweet.getUser().getScreenName()); } ArrayList<String> profileimg = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { profileimg.add(tweet.getUser().getBiggerProfileImageURL()); } ArrayList<String> username = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getName() + "<br>" + "@" + tweet.getUser().getScreenName()); } ArrayList<String> usernameURL = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getURL()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); ArrayList<String> resulttweet = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { resulttweet.add(tweet.getText() + "<br>" + sdf.format(tweet.getCreatedAt())); } request.setAttribute("search", search); request.setAttribute("userID", userID); request.setAttribute("profileimg", profileimg); request.setAttribute("username", username); request.setAttribute("resulttweet", resulttweet); request.setAttribute("usernameURL", usernameURL); request.getRequestDispatcher("/mypage.jsp").forward(request, response); }
From source file:Origin.Searchtweet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);// w ww . j a v a2 s .c om cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User user = twitter.verifyCredentials(); request.setCharacterEncoding("UTF-8"); String search = "?" + request.getParameter("searchtweet"); //String search= request.getParameter("searchtweet"); Query query = new Query(); query.setCount(100); query.setQuery(search); QueryResult queryresult = null; try { queryresult = twitter.search(query); } catch (TwitterException e1) { e1.printStackTrace(); } ArrayList<String> userID = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { userID.add(tweet.getUser().getScreenName()); } ArrayList<String> profileimg = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { profileimg.add(tweet.getUser().getBiggerProfileImageURL()); } ArrayList<String> username = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getName() + "<br>" + "@" + tweet.getUser().getScreenName()); } ArrayList<String> usernameURL = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getURL()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); ArrayList<String> resulttweet = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { resulttweet.add(tweet.getText() + "<br>" + sdf.format(tweet.getCreatedAt())); } request.setAttribute("search", search); request.setAttribute("userID", userID); request.setAttribute("profileimg", profileimg); request.setAttribute("username", username); request.setAttribute("resulttweet", resulttweet); request.setAttribute("usernameURL", usernameURL); request.getRequestDispatcher("/searchtweet.jsp").forward(request, response); }
From source file:Principal.Tracker_Twitter.java
License:Minecraft Mod Public
public void guardarResultados_Twitter(List<ObjetoBuscar> lista, BD base, int contadorBase, int TokenIndice) throws NoSuchAlgorithmException, KeyManagementException { int nuevoContadorBase = 0; if (contadorBase >= lista.size()) { System.out.println("Termino en:" + contadorBase); } else {//from w w w. j a v a 2s.c o m System.out.println("---------------------------------------------------------------------:P"); TrustManager[] trustAllCerts = { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); System.out.println("Token : " + TokenIndice); System.out.println(consumerKey[TokenIndice]); try { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey[TokenIndice]); cb.setOAuthConsumerSecret(this.consumerSecret[TokenIndice]); cb.setOAuthAccessToken(this.token[TokenIndice]); cb.setOAuthAccessTokenSecret(this.tokenSecret[TokenIndice]); Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance(); for (int numtTweets = contadorBase; numtTweets < contadorBase + 5; numtTweets++) { if (((ObjetoBuscar) lista.get(numtTweets)).getUrl().equals("") || ((ObjetoBuscar) lista.get(numtTweets)).getUrl() == null) { } else { System.out.println("Usuario: " + ((ObjetoBuscar) lista.get(numtTweets)).getUrl()); String usuariosinArroba = ((ObjetoBuscar) lista.get(numtTweets)).getUrl().replace("@", ""); System.out.println("" + usuariosinArroba); try { User usuario = unauthenticatedTwitter.showUser(usuariosinArroba); List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe(); List<Status> favoritos = unauthenticatedTwitter.getFavorites(); Paging paging = new Paging(1, 1000); ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(), paging); System.out.println("Followers: " + usuario.getFollowersCount()); System.out.println("Yo sigo: " + usuario.getFriendsCount()); List<String> listaTweets = new ArrayList(); List<Long> ListaRettewts = new ArrayList(); List<Integer> ListaFavoritos = new ArrayList(); List<Integer> ListaMenciones = new ArrayList(); List<Date> ListaFecha = new ArrayList(); List<Long> ListaIds = new ArrayList(); for (Status sta : statuses) { ListaIds.add(Long.valueOf(sta.getId())); listaTweets.add(sta.getText()); ListaRettewts.add(Long.valueOf(Long.parseLong(sta.getRetweetCount() + ""))); ListaMenciones.add(Integer.valueOf(sta.getUserMentionEntities().length)); ListaFecha.add(sta.getCreatedAt()); ListaFavoritos.add(Integer.valueOf(sta.getFavoriteCount())); } for (int i = 0; i < listaTweets.size(); i++) { base.guardarTrackTwitter_Log((Long) ListaIds.get(i), ((ObjetoBuscar) lista.get(numtTweets)).getUrl(), (String) listaTweets.get(i), (Date) ListaFecha.get(i), (Long) ListaRettewts.get(i), ((Integer) ListaFavoritos.get(i)).intValue(), ((Integer) ListaMenciones.get(i)).intValue()); } } catch (Exception e) { System.err.println("Entro al Try por :" + e); } nuevoContadorBase = numtTweets; } } System.out.println("Numero de Contador Base:" + nuevoContadorBase); guardarResultados_Twitter(lista, base, nuevoContadorBase + 1, TokenIndice + 1); } catch (NumberFormatException e) { System.err.println("Fallo por :" + e); } } }
From source file:public_streaming.SampleStream.java
License:Apache License
public void onStatus(Status status) { System.out.println("tweet:" + status.getText());// System.out.println(status.getFavoriteCount()); System.out.println("User" + status.getUser().getName() + "@" + status.getUser().getScreenName());//??,?(@xx) System.out.println("Posted Time:" + status.getCreatedAt());// System.out.println("Application Name:" + status.getSource());// System.out.println("Time Zone:" + status.getUser().getTimeZone());// System.out.println("Created Date:" + status.getUser().getCreatedAt());//? System.out.println("GeoLocation:" + status.getUser().getLocation());//? System.out.println("postID:" + status.getId());//ID System.out.println("UserID" + status.getUser().getId());//ID System.out.println("Language:" + status.getUser().getLang());// System.out.println("Follow:" + status.getUser().getFriendsCount());// System.out.println("Follower:" + status.getUser().getFollowersCount());// }
From source file:rtb.PopularTweetCollector.java
License:Apache License
/** * Write out the list of tweets to JSON form. * @param statuses the list of statuses//from w ww .j av a2s. c om * @param fileName JSON file name * @throws JsonParseException * @throws IOException */ public void writeAsJson(List<? extends Status> statuses, String fileName) throws JsonParseException, IOException { if (statuses == null || fileName == null) throw new NullPointerException(); if (statuses.isEmpty()) return; // Convert Status to TweetPojo List<Tweet> pojos = new ArrayList<>(statuses.size()); for (Status s : statuses) { // Get tweet text String text = s.getText().replaceAll("[\n\t]", " "); // Get formatted date text DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String date = formatter.format(s.getCreatedAt()); String screenName = s.getUser().getScreenName(); pojos.add(new Tweet(screenName, text, date, s.getFavoriteCount(), getTweetURL(s))); } // Write out TweetPojo as JSON FileWriter writer = new FileWriter(new File(fileName)); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(writer, pojos); }
From source file:ru.mail.sphere.java_hw5_vasilyev.twitteraccessor.Accessor.java
private static Tweet buildTweetFromStatus(final Status status) { return new Tweet(status.getText(), status.getCreatedAt(), status.getFavoriteCount(), status.getRetweetCount(), status.getLang()); }
From source file:sentimentanalysis.Twitter.GetTweets.java
public static void main(String args[]) { Twitter4JConfig t4jConfig = new Twitter4JConfig(); ConfigurationBuilder cb = t4jConfig.getConfigurationBuilder(); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();/*ww w . ja va2s . co m*/ String keyword = "Trump"; ArrayList<Post> TweetResultList = new ArrayList<Post>(); int count = 0; try { Query query = new Query(keyword + "+exclude:retweets+lang:en").until("2016-11-19"); QueryResult result; do { result = twitter.search(query); ArrayList<Status> tweets = (ArrayList<Status>) result.getTweets(); for (Status tweet : tweets) { count++; String user = tweet.getUser().getScreenName(); String content = tweet.getText(); Date time = tweet.getCreatedAt(); System.out.println(time.getTime()); String tweet_url = "https://twitter.com/" + tweet.getUser().getScreenName() + "/status/" + tweet.getId(); System.out.println(tweet.getLang()); Post tr = new Post(user, content, tweet_url, new java.sql.Date(time.getTime())); TweetResultList.add(tr); // System.out.println("[user]@" + tweet.getUser().getScreenName() // + "[/user][tweet]" + tweet.getText()+"[/tweet][link]"+tweet_url+"[/link]"); } } while (((query = result.nextQuery()) != null) && (count < 500)); try { SaveToDB.savePosts(TweetResultList); } catch (SQLException ex) { java.util.logging.Logger.getLogger(GetTweets.class.getName()).log(Level.SEVERE, null, ex); } } catch (TwitterException te) { te.printStackTrace(); } }