List of usage examples for twitter4j Status getText
String getText();
From source file:examendetwitter.metodostwitter.java
/** * Busca tweets con el texto introducido *//*from w ww .j a v a 2 s . c om*/ public void buscarTrending(String busqueda) throws TwitterException { Query query = new Query(busqueda); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); } }
From source file:examendetwitter.metodostwitter.java
/** * Crea y publica un tweet//from ww w .ja va 2s . c om */ public void tweetear(String tweet) throws TwitterException { Status status = twitter.updateStatus(tweet); System.out.println("Successfully updated the status to [" + status.getText() + "]."); }
From source file:examentwittercod.MetodosTwitter.java
/** * Nos da nuestro timeLine/*from w ww . j av a 2s .co m*/ */ public void verTL() throws TwitterException { List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Mostrando Linea del Tiempo."); for (Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); } }
From source file:example.justids.java
License:Apache License
/** * Usage: java twitter4j.examples.search.SearchTweets [query] * * @param args/*from w w w . ja v a 2 s .c om*/ */ public static void main(String[] args) { StatusListener listener = new StatusListener() { public Double count = 0d; Date started = new Date(); Date previous = new Date(); @Override public void onStatus(Status status) { try { File file = new File("Filtered_over1percent_lab_pc_obama_all.txt"); File file2 = new File("Filtered_over1percent_lab_pc_obama.txt"); // if file doesnt exists, then create it FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); FileWriter fw2 = new FileWriter(file2.getAbsoluteFile(), true); BufferedWriter bw2 = new BufferedWriter(fw2); if (this.count % 1000 == 0) { Date finished10k = new Date(); System.out.println("\n\n\n\n AVERAGE RATE OF TWEETS is " + (this.count * 1000 / (finished10k.getTime() - this.started.getTime()))); System.out.println(1000000d / (finished10k.getTime() - this.previous.getTime())); System.out.println(this.count); System.out.println(finished10k.getTime() + " " + this.started.getTime() + " " + (finished10k.getTime() - this.started.getTime())); System.out.println(finished10k.getTime() + " " + this.previous.getTime() + " " + (finished10k.getTime() - this.previous.getTime())); System.out.println(status.getSource()); System.out.println("\n\n\n\n"); this.previous = finished10k; } this.count++; // System.out.println(status.getUser().getName() + " : " + status.getText()+" "+ this.count); bw.write(status.getId() + "\n"); bw.close(); if (status.getText().contains("obama")) { bw2.write(status.getId() + "\n"); bw2.close(); } } catch (IOException e) { e.printStackTrace(); } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // System.out.println(statusDeletionNotice.getUserId()+" has deleted this tweet"); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println(numberOfLimitedStatuses + " are missing from here"); } @Override public void onException(Exception ex) { ex.printStackTrace(); } @Override public void onScrubGeo(long arg0, long arg1) { // TODO Auto-generated method stub } @Override public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); RawStreamListener rawst = new RawStreamListener() { public Double count = 0d; public Double lengthsum = 0d; Date started = new Date(); Date previous = new Date(); @Override public void onMessage(String message) { if (!message.startsWith("{\"delete")) { count++; lengthsum += message.length(); if (count % 1000 == 0) { System.out.println(lengthsum / count); // lengthsum=0d; // count=0d; } } // TODO Auto-generated method stub } @Override public void onException(Exception arg0) { // TODO Auto-generated method stub } }; // twitterStream.addListener(rawst); String[] searchfor = { "language", "people", "problem", "microsoft", "epidemic", "obama", "zoo" }; FilterQuery query = new FilterQuery(); query.track(searchfor); twitterStream.addListener(listener); twitterStream.filter(query); // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. // twitterStream.sample(); }
From source file:example.search.java
License:Apache License
/** * Usage: java twitter4j.examples.search.SearchTweets [query] * * @param args/*from w w w. ja v a2 s .c om*/ */ public static void main(String[] args) { StatusListener listener = new StatusListener() { public Double count = 0d; Date started = new Date(); Date previous = new Date(); @Override public void onStatus(Status status) { try { File file = new File("whythissucks.txt"); // if file doesnt exists, then create it FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); if (this.count % 1000 == 0) { Date finished10k = new Date(); System.out.println("\n\n\n\n AVERAGE RATE OF TWEETS is " + (this.count * 1000 / (finished10k.getTime() - this.started.getTime()))); System.out.println(1000000d / (finished10k.getTime() - this.previous.getTime())); System.out.println(this.count); System.out.println(finished10k.getTime() + " " + this.started.getTime() + " " + (finished10k.getTime() - this.started.getTime())); System.out.println(finished10k.getTime() + " " + this.previous.getTime() + " " + (finished10k.getTime() - this.previous.getTime())); System.out.println(status.getSource()); System.out.println("\n\n\n\n"); this.previous = finished10k; } this.count++; // System.out.println(status.getUser().getName() + " : " + status.getText()+" "+ this.count); bw.write(status.getId() + "|" + status.getText() + "\n"); bw.close(); } catch (IOException e) { e.printStackTrace(); } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // System.out.println(statusDeletionNotice.getUserId()+" has deleted this tweet"); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("limited " + numberOfLimitedStatuses); } @Override public void onException(Exception ex) { ex.printStackTrace(); } @Override public void onScrubGeo(long arg0, long arg1) { // TODO Auto-generated method stub } @Override public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub System.out.println(arg0.getMessage()); } }; TwitterInstanceCreator tic = new TwitterInstanceCreator(); RawStreamListener rawst = new RawStreamListener() { public Double count = 0d; public Double lengthsum = 0d; Date started = new Date(); Date previous = new Date(); String filename; String previousfilename = ""; @Override public void onMessage(String message) { if (!message.startsWith("{\"delete")) { try { // if file doesnt exists, then create it if (this.count % 1000 == 0) { Date finished10k = new Date(); System.out.println("\n\n\n\n AVERAGE RATE OF TWEETS is " + (this.count * 1000 / (finished10k.getTime() - this.started.getTime()))); System.out.println(1000000d / (finished10k.getTime() - this.previous.getTime())); System.out.println(this.count); System.out.println(finished10k.getTime() + " " + this.started.getTime() + " " + (finished10k.getTime() - this.started.getTime())); System.out.println(finished10k.getTime() + " " + this.previous.getTime() + " " + (finished10k.getTime() - this.previous.getTime())); System.out.println("\n\n\n\n"); this.previous = finished10k; } File file = new File("tweetstoimport/" + this.filename); FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); this.count++; // System.out.println(status.getUser().getName() + " : " + status.getText()+" "+ this.count); bw.write(message + "\n"); bw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } // TODO Auto-generated method stub } @Override public void onException(Exception arg0) { // TODO Auto-generated method stub } }; // twitterStream.addListener(rawst); // String[] searchfor={"flu", "influenza", "fever", "cough", "sore", "throat", "sore throat", "headache"}; // FilterQuery query=new FilterQuery(); // query.track(searchfor); TwitterStream twitterStream = tic.getStream(1); twitterStream.addListener(listener); // twitterStream.filter(query); // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. twitterStream.sample(); //Filters from the stream //twitterStream.filter(query); }
From source file:examples.GetUserListStatuses.java
License:Apache License
/** * Usage: java twitter4j.examples.list.GetUserListStatuses [list id] * * @param args message// w w w. j a va2 s . c o m */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.list.GetUserListStatuses [list id]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); Paging page = new Paging(1); ResponseList<Status> statuses; do { statuses = twitter.getUserListStatuses(Integer.parseInt(args[0]), page); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } page.setPage(page.getPage() + 1); } while (statuses.size() > 0 && page.getPage() <= 10); System.out.println("done."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to list statuses: " + te.getMessage()); System.exit(-1); } }
From source file:ezbake.training.TweetIngestParser.java
License:Apache License
private Tweet convertToTweet(Status status) { Tweet tweet = new Tweet(); tweet.setTimestamp(status.getCreatedAt().getTime()); tweet.setId(status.getId());/*from w w w .j a v a 2 s . c om*/ tweet.setText(status.getText()); tweet.setUserId(status.getUser().getId()); tweet.setUserName(status.getUser().getName()); tweet.setIsFavorite(status.isFavorited()); tweet.setIsRetweet(status.isRetweet()); if (status.getGeoLocation() != null) { tweet.setGeoLocation( new Coordinate(status.getGeoLocation().getLatitude(), status.getGeoLocation().getLongitude())); } return tweet; }
From source file:flight_ranker.Flight_colllector.java
public static void main(String[] args) throws FileNotFoundException, IOException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);//from w w w . j av a 2 s .c o m cb.setOAuthConsumerKey("Oa6WAzH0j3sgVrP0CNGvxnWA2"); cb.setOAuthConsumerSecret("sLdoFybvJvVFz7Lxbbv9KWQDFeKcVeZAkWDC4QMHnx5lV2OmGE"); cb.setOAuthAccessToken("2691889945-5NOBWKUgT9FiAoyOQSCFg8CLlPRlDMbWcUrJBdK"); cb.setOAuthAccessTokenSecret("J6tA8Sxrtz2JNSFdQwAonbGxNfLNuD9I54Zfvomku3p5t"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onException(Exception arg0) { // TODO Auto-generated method stub } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { // TODO Auto-generated method stub } @Override public void onScrubGeo(long arg0, long arg1) { // TODO Auto-generated method stub } @Override public void onStatus(Status status) { User user = status.getUser(); // gets Username String username = status.getUser().getScreenName(); long followers = user.getFollowersCount(); long retweets = status.getRetweetCount(); long favs = status.getFavoriteCount(); System.out.println("USERNAME--> " + username); System.out.println("FOLLOWERS--> " + followers); String profileLocation = user.getLocation(); // System.out.println("RETWEETS--> "+retweets); // System.out.println("FAVOURITES--> "+favs); System.out.println("LOCATION--> " + profileLocation); long tweetId = status.getId(); System.out.println("TWEET ID--> " + tweetId); String content = status.getText(); System.out.println("TWEET--> " + content + "\n"); BufferedWriter b1 = null, b2, b3, b4, b5, b6, b7 = null; try { //output_file = new BufferedReader(new FileReader("G:\\Sentiwords.txt")); FileWriter f1 = new FileWriter("G:\\flights_data.txt", true); b1 = new BufferedWriter(f1); b1.write("#USERNAME- " + username); b1.newLine(); b1.write("#Followers- " + followers); b1.newLine(); b1.write("#Location- " + profileLocation); b1.newLine(); b1.write("#ID- " + tweetId); b1.newLine(); b1.write("#Tweet- " + content); b1.newLine(); b1.newLine(); tweet_editor modified_tweet = new tweet_editor(content); //tweet_tagger tagged_tweet = new tweet_tagger(modified_tweet.edited_tweet); //System.out.println(tagged_tweet.tagged); sentiment_calculator senti_value = new sentiment_calculator(modified_tweet.edited_tweet); if (content.contains("Indigo")) { System.out.println("indigo"); FileWriter f2 = new FileWriter("G:\\Indigo.txt", true); b2 = new BufferedWriter(f2); b2.write(Double.toString(senti_value.senti_rate)); b2.newLine(); } if (content.contains("Jet")) { System.out.println("jet"); FileWriter f3 = new FileWriter("G:\\jet.txt", true); b3 = new BufferedWriter(f3); b3.write(Double.toString(senti_value.senti_rate)); b3.newLine(); } if (content.contains("Indian")) { System.out.println("indian"); FileWriter f4 = new FileWriter("G:\\Indian.txt", true); b4 = new BufferedWriter(f4); b4.write(Double.toString(senti_value.senti_rate)); b4.newLine(); } if (content.contains("Spicejet")) { System.out.println("spicejet"); FileWriter f5 = new FileWriter("G:\\spicejet.txt", true); b5 = new BufferedWriter(f5); b5.write(Double.toString(senti_value.senti_rate)); b5.newLine(); } if (content.contains("AirAsia")) { System.out.println("airasia"); FileWriter f6 = new FileWriter("G:\\airasia.txt", true); b6 = new BufferedWriter(f6); b6.write(Double.toString(senti_value.senti_rate)); b6.newLine(); } try { //output_file = new BufferedReader(new FileReader("G:\\Sentiwords.txt")); FileWriter f7 = new FileWriter("G:\\flight_senti.txt", true); b7 = new BufferedWriter(f7); b7.write(String.valueOf(senti_value.senti_rate)); b7.newLine(); } catch (IOException e) { e.printStackTrace(); } finally { try { b7.close(); } catch (IOException ex) { Logger.getLogger(Flight_colllector.class.getName()).log(Level.SEVERE, null, ex); } } } catch (IOException e) { e.printStackTrace(); } finally { try { b1.close(); } catch (IOException ex) { Logger.getLogger(Flight_colllector.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onTrackLimitationNotice(int arg0) { // TODO Auto-generated method stub } @Override public void onStallWarning(StallWarning sw) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; FilterQuery fq = new FilterQuery(); String keywords[] = { "Indian Airlines, Indigo Airlines, Indigo Airline , Indian Airline , Spicejet , jetAirways , Jet Airways, Jet Airlines , airasia" }; //we will pass stock related keyword here fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); }
From source file:foo.bar.twitter.sample01.Sample01Activity.java
License:Apache License
/** * start button clicked//from w ww . j a v a 2 s . c om * @param v */ public void onClickStartButton(View v) { Log.d("DEBUG", "Start button clicked!"); if (!isAuthorized) { Log.d("DEBUG", "not authorized"); return; } bt_start.setEnabled(false); //start button disabled bt_cancel.setEnabled(true); //cancel button enabled if (isAuthorized) { twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(ConstantValue.CONSUMER_KEY, ConstantValue.CONSUMER_SECRET); twitterStream.setOAuthAccessToken(new AccessToken(token, tokenSecret)); StatusListener listener = new StatusListener() { @Override public void onException(Exception arg0) { ;//no process } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { ;//no process } @Override public void onScrubGeo(long arg0, long arg1) { ;//no process } @Override public void onStatus(Status status) { String tweet = status.getText(); Log.d("DEBUG", "tweet: " + tweet); } @Override public void onTrackLimitationNotice(int arg0) { ;//no process } }; twitterStream.addListener(listener); String[] trackArray = { ConstantValue.HASH_TAG }; twitterStream.filter(new FilterQuery(0, null, trackArray)); } }
From source file:fr.istic.taa.jaxrs.StatusEndpoint.java
License:Apache License
@GET @Path("/postTweet") @Produces(MediaType.APPLICATION_JSON)/* w w w.java 2s . c o m*/ public String getTweet() throws IOException, TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("jUTzyyI3zjBqiKQqhfQyFeqpm") .setOAuthConsumerSecret("gMkOSO9EYqlzrnq35kdoZIqvX12sJwP1wHKMqo6uYbvq2q0LGl") .setOAuthAccessToken("89767958-C2cLIz69SpdR6wmQGdzE8rQSXAMzIVBpYOuaZGmHQ") .setOAuthAccessTokenSecret("oG7FQJMQsX2OHKxcaHjUxgZI94ZqUShGi0qCAsI50xfpZ"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); String latestStatus = "TEST55555555"; Status status = twitter.updateStatus(latestStatus); System.out.println("Successfully updated the status to [" + status.getText() + "]."); return "Successfully updated status to " + status.getText(); }