List of usage examples for twitter4j Status getText
String getText();
From source file:PrintRetweetStream.java
License:Apache License
/** * Main entry of this application.// w w w . j a v a2 s. c o m * * @param args arguments doesn't take effect with this example * @throws TwitterException when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(""); cb.setOAuthConsumerSecret(""); cb.setOAuthAccessToken(""); cb.setOAuthAccessTokenSecret(""); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; twitterStream.addListener(listener); twitterStream.retweet(); }
From source file:TimeLine.java
private void btTwitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTwitActionPerformed // Tombol update status, show setelah update txtStatus.setText(""); TwitterFactory tf = new TwitterFactory(); Twitter twitter = tf.getInstance();// ww w.j a va2 s. c o m try { Status status = twitter.updateStatus(txStatus.getText()); JOptionPane.showMessageDialog(rootPane, "Twit \n [ " + status.getText() + " ]\nTerkirim!"); } catch (TwitterException ex) { JOptionPane.showMessageDialog(rootPane, "Tidak bisa mengirim : " + ex.getMessage()); Logger.getLogger(TimeLine.class.getName()).log(Level.SEVERE, null, ex); } List<Status> statuses = null; try { statuses = twitter.getUserTimeline(); statuses.stream().forEach((status) -> { txtStatus.append(status.getUser().getName() + " : " + status.getText() + " - " + status.getCreatedAt() + " \n Via : " + status.getSource() + "\n\n"); }); txStatus.setText(""); //reload field } catch (TwitterException te) { JOptionPane.showMessageDialog(rootPane, "Failed to Show Status!" + te.getMessage()); } }
From source file:TwitterGateway.java
@Override public void onStatus(Status status) { user = status.getUser().getScreenName(); String mentionStatus = status.getText(); System.out.println("@" + user + " - " + mentionStatus); String paramScreenName = screenName.toLowerCase(); mentionStatus = mentionStatus.toLowerCase().replace(paramScreenName, "").trim(); String locale = new String(); if (mentionStatus.contains(" to ")) { location = mentionStatus.split(" to "); locale = "en"; } else if (mentionStatus.contains(" ke ")) { location = mentionStatus.split(" ke "); locale = "id"; } else {//from w ww .j av a 2s.co m location = null; } boolean statusLocation1 = false; boolean statusLocation2 = false; if (mentionStatus.equals("help") || mentionStatus.equals(("bantuan"))) { try { if (mentionStatus.equals("help")) { Tweet(user, "For using this Twitter bot for searching public transport route, you can mention..."); Tweet(user, "'First location' to 'second location', example : BIP to PVJ"); } else { Tweet(user, "Format penggunaan Twitter bot untuk mencari jalur transportasi publik adalah..."); Tweet(user, "'Lokasi awal' ke 'lokasi tujuan', contoh : BIP ke PVJ."); } } catch (TwitterException ex) { System.out.println("Tweet help error"); } } else if (location.length == 2 && !location[0].contains("@") && !location[1].contains("@")) { try { if (location[0].equals(location[1])) { if (locale.equals("id")) { Tweet(user, "Pencarian tidak dapat dilakukan karena lokasi awal dan lokasi tujuan sama"); } else if (locale.equals("en")) { Tweet(user, "Route can't be found. Starting location and destination are similar"); } } else { System.out.println("Lokasi 1 : " + location[0].trim()); System.out.println("Lokasi 2 : " + location[1].trim()); //string destination menampung hasil dari JSONObject hasil pencarian apa saja yang ditemukan dari KIRIGateway.getLatLong String destination1 = KIRIGateway.GetLatLong(location[0]); String destination2 = KIRIGateway.GetLatLong(location[1]); //dimasukan ke JSONObject JSONObject objDest1 = new JSONObject(destination1); JSONObject objDest2 = new JSONObject(destination2); //memasukan hasil pencarian pertama dari JSONObject ke abribut routingResponse JSONObject res1 = objDest1.getJSONArray("searchresult").getJSONObject(0); String hasilDest1 = res1.getString("placename"); latlon[0] = res1.getString("location"); if (hasilDest1 != null) { statusLocation1 = true; } JSONObject res2 = objDest2.getJSONArray("searchresult").getJSONObject(0); String hasilDest2 = res2.getString("placename"); latlon[1] = res2.getString("location"); if (hasilDest2 != null) { statusLocation2 = true; } //Mendapatkan hasil pencarian lalu dimasukan ke JSONArray paramSteps untuk dipisah-pisah lalu dimasukan ke RoutingResponse String hasilPencarian = KIRIGateway.GetTrack(latlon[0], latlon[1], locale); JSONObject objTrack = new JSONObject(hasilPencarian); JSONObject routingresults = objTrack.getJSONArray("routingresults").getJSONObject(0); JSONArray paramSteps = routingresults.getJSONArray("steps"); //buat variable step, steps, dan routing response step = new Step[paramSteps.length()]; for (int i = 0; i < step.length; i++) { step[i] = new Step(paramSteps.getJSONArray(i).getString(3) + ""); } steps = new Steps(step); routingResponse = new RoutingResponse(objTrack.getString("status"), steps); if (routingResponse.getStatus().equals("ok")) { for (int i = 0; i < routingResponse.getRoutingResult().getSteps().length; i++) { date = new Date(); Tweet(user, routingResponse.getRoutingResult().getSteps()[i].getHumanDescription()); } if (locale.equals("id")) { Tweet(user, "Untuk lebih lengkapnya dapat dilihat pada http://kiri.travel?start=" + location[0].replace(" ", "%20") + "&finish=" + location[1].replace(" ", "%20") + "®ion=bdo"); } else if (locale.equals("en")) { Tweet(user, "For futher information you can visit http://kiri.travel?start=" + location[0].replace(" ", "%20") + "&finish=" + location[1].replace(" ", "%20") + "®ion=bdo"); } for (int i = 0; i < routingResponse.getRoutingResult().getSteps().length; i++) { System.out.println("@" + user + " " + routingResponse.getRoutingResult().getSteps()[i].getHumanDescription()); } System.out.println( "@" + user + " Untuk lebih lengkap silahkan lihat di http://kiri.travel?start=" + location[0].replace(" ", "%20") + "&finish=" + location[1].replace(" ", "%20") + "®ion=bdo"); } else { System.out.println("status error"); } } } catch (Exception ex) { try { if (!statusLocation1) { date = new Date(); Tweet(user, location[0] + " tidak ditemukan"); System.out.println("@" + user + " " + location[0] + " tidak ditemukan"); } else if (!statusLocation2) { date = new Date(); Tweet(user, location[1] + " tidak ditemukan"); System.out.println("@" + user + " " + location[1] + " tidak ditemukan"); } else { date = new Date(); Tweet(user, "Gangguan Koneksi"); System.out.println("Gangguan Koneksi"); } //java.util.logging.Logger.getLogger(TwitterGateway.class.getName()).log(Level.SEVERE, null, ex); } catch (TwitterException ex1) { System.out.println("Error2"); java.util.logging.Logger.getLogger(TwitterGateway.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:NewMain.java
/** * @param args the command line arguments *///from w w w. j a v a 2 s.co m public static void main(String[] args) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); ResponseList<twitter4j.Status> statuses = twitter.getHomeTimeline(); System.out.println("Mostrando el timeline..."); for (twitter4j.Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + ": " + status.getText()); } }
From source file:Read_data.java
/** * @param args the command line arguments * @throws twitter4j.TwitterException//w w w . j a v a 2s .c o m * @throws java.io.FileNotFoundException */ public static void main(String[] args) throws TwitterException, FileNotFoundException, IOException { // TODO code application logic here ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(customer_key).setOAuthConsumerSecret(customer_secret) .setOAuthAccessToken(access_token).setOAuthAccessTokenSecret(access_token_secret); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onStatus(Status status) { //get the place if it is not null if (status.getPlace() != null) { try { String place = status.getPlace().getName(); System.out.println("Place: " + place + "\t\t\t" + "Tweet: " + status.getText()); Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(Read_data.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { System.out.print(""); } @Override public void onTrackLimitationNotice(int i) { System.out.print(""); } @Override public void onScrubGeo(long l, long l1) { System.out.print(""); } @Override public void onStallWarning(StallWarning sw) { System.out.println(sw); } @Override public void onException(Exception ex) { System.out.println(ex); } }; FilterQuery fq = new FilterQuery(); //Stream tweets with these keywords. Replace for your tweets that you are looking for. String keywords[] = { "lol", "lls", "lmao", "llf" }; fq.track(keywords); twitterStream.addListener(statusListener); twitterStream.filter(fq); try { synchronized (lock) { lock.wait(); } } catch (InterruptedException e) { System.out.println(e); } System.out.println("returning statuses"); // twitterStream.shutdown(); }
From source file:MapDemo.java
public static void main(String[] args) throws TwitterException, IOException, Exception { TwitterFactory tf = new TwitterFactory(); Twitter twitter = tf.getInstance();//from w w w . j a va 2 s. co m boolean flag = true; // Ask the user for a search string. String searchStr = "ParkandGoUNL"; // Create a Query object. Query query = new Query(searchStr); // Send API request to execute a search with the given query. QueryResult result = twitter.search(query); // Display search results. result.getTweets().stream().forEach((Status status) -> { System.out.println("\n" + status.getText() + status.getCreatedAt()); }); if (flag) { GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyArz1NljiDpuOriFWalOerYEdHOyi8ow8Y"); List<Marker> markers = new ArrayList<>(); Marker e = new Marker(GeocodingApi.geocode(context, "616 North 16th Street, Lincoln, Nebraska, USA") .await()[0].geometry.location, "marker1", "KKG", new Date()); markers.add(e); StreetExtractor se = new StreetExtractor(); List<Address> address = se.find("Park and Go 601 North 16th Street"); address.forEach(((Address a) -> { try { Marker m = new Marker( GeocodingApi.geocode(context, a.getAddress()).await()[0].geometry.location, "marker0", "A Tweet", new Date()); markers.add(m); } catch (Exception ex) { Logger.getLogger(MapDemo.class.getName()).log(Level.SEVERE, null, ex); } })); Map map = new Map(markers); map.create(); } }
From source file:PrintLinksStream.java
License:Apache License
/** * Main entry of this application./*w w w.j av a 2 s. com*/ * * @param args arguments doesn't take effect with this example * @throws TwitterException when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(""); cb.setOAuthConsumerSecret(""); cb.setOAuthAccessToken(""); cb.setOAuthAccessTokenSecret(""); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; twitterStream.addListener(listener); twitterStream.links(0); }
From source file:PrintSampleStream.java
License:Apache License
/** * Main entry of this application.// ww w.j a va 2 s .com * * @param args arguments doesn't take effect with this example * @throws TwitterException when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(""); cb.setOAuthConsumerSecret(""); cb.setOAuthAccessToken(""); cb.setOAuthAccessTokenSecret(""); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; twitterStream.addListener(listener); twitterStream.sample(); }
From source file:TweetMapManager.java
public static void main(String[] args) { TwitterFactory tf = new TwitterFactory(); Twitter twitter = tf.getInstance();//from w w w .j av a2 s . c o m String searchStr = "#ParkandGoUNL"; Query query = new Query(searchStr); GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyArz1NljiDpuOriFWalOerYEdHOyi8ow8Y"); List<Marker> markers = new LinkedList<>(); StreetExtractor se = new StreetExtractor(); LocalTime now = LocalTime.now(); while (true) { DayOfWeek today = LocalDate.now().getDayOfWeek(); if (today.getValue() < WEEKEND) { if (now.isAfter(STARTTIME) && now.isBefore(ENDTIME)) { // Send API request to execute a search with the given query. QueryResult results = null; try { results = twitter.search(query); } catch (TwitterException ex) { LOGGER.warn(ex.getMessage()); } // Display search results. if (results != null) { results.getTweets().stream().forEach((Status status) -> { try { Date created = status.getCreatedAt(); String text = status.getText(); LOGGER.info(status.getText()); LatLng location; if (status.getGeoLocation() != null) { location = new LatLng(status.getGeoLocation().getLatitude(), status.getGeoLocation().getLongitude()); } else { String modified = text.replace("#ParkAndGoUNL", ""); List<Address> address = se.find(modified); location = GeocodingApi.geocode(context, address.get(0).getAddress()) .await()[0].geometry.location; } String id = UUID.randomUUID().toString().substring(0, 8); Marker m = new Marker(location, "m" + id, text, created); markers.add(m); } catch (Exception ex) { LOGGER.warn(ex.getMessage()); } }); } if (!markers.isEmpty()) { Marker m = markers.get(markers.size() - 1); if (m.getTimestamp().getTime() < Time.valueOf(now.minusMinutes(30)).getTime()) { DailyLogs.addMarkerToLog(m, today); markers.remove(m); } } Map map = new Map(markers); map.create(); } else { //wait 5 hours try { LOGGER.info("Sleeping 5 hours"); Thread.sleep((long) 1.8e+7); } catch (InterruptedException ex) { LOGGER.warn(ex.getMessage()); } } now = LocalTime.now(); } else { try { //Wait a day LOGGER.info("Sleeping 1 day"); Thread.sleep((long) 8.64e+7); } catch (InterruptedException ex) { LOGGER.warn(ex.getMessage()); } } try { LOGGER.info("Successful Loop, Resting"); Thread.sleep(1000); } catch (InterruptedException ex) { LOGGER.warn(ex.getMessage()); } } }
From source file:twitterGateway_v2_06.java
License:Creative Commons License
public void SetupTwitter() { //twitterIn = new TwitterConnectStream(); //accessToken = new AccessToken(TwitterAccessToken, TwitterAccessTokenSecret); //TwitterOAuthAuthorization.setOAuthAccessToken(accessToken); //TwitterOAuthAuthorization = new OAuthAuthorization(conf); //TwitterOAuthAuthorization.setOAuthConsumer(TwitterConsumerKey, TwitterConsumerSecret); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(TwitterConsumerKey) .setOAuthConsumerSecret(TwitterConsumerSecret).setOAuthAccessToken(TwitterAccessToken) .setOAuthAccessTokenSecret(TwitterAccessTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); twitterOut = tf.getInstance();//from w w w . j ava 2s . c o m // try { // twitterOut.updateStatus("Hello World!"); // } // catch (TwitterException ex) { // println(ex); // } ActivityLogAddLine("twitter connector ready"); output = createWriter("log.txt"); StatusListener twitterIn = new StatusListener() { public void onStatus(Status status) { double Longitude; double Latitude; GeoLocation GeoLoc = status.getGeoLocation(); if (GeoLoc != null) { //println("YES got a location"); Longitude = GeoLoc.getLongitude(); Latitude = GeoLoc.getLatitude(); } else { Longitude = 0; Latitude = 0; } println(TimeStamp() + "\t" + Latitude + "\t" + Longitude + "\t" + status.getUser().getScreenName() + "\t" + status.getText()); output.println(TimeStamp() + "\t" + Latitude + "\t" + Longitude + "\t" + status.getUser().getScreenName() + "\t" + status.getText()); output.flush(); TwitterToOsc(status.getUser().getScreenName(), status.getText()); } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } public void onException(Exception ex) { println("CAUGHT in the ACT: " + ex); } }; ConfigurationBuilder cbIn = new ConfigurationBuilder(); cbIn.setDebugEnabled(true).setOAuthConsumerKey(TwitterConsumerKey) .setOAuthConsumerSecret(TwitterConsumerSecret).setOAuthAccessToken(TwitterAccessToken) .setOAuthAccessTokenSecret(TwitterAccessTokenSecret); TwitterStreamFactory ts = new TwitterStreamFactory(cbIn.build()); TwitterStream twitterStream = ts.getInstance(); twitterStream.addListener(twitterIn); // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. FilterQuery twitterFilter = new FilterQuery(0, TwitterFollowIDs, TwitterTrackWords); twitterStream.filter(twitterFilter); }