List of usage examples for twitter4j Status getText
String getText();
From source file:crawltweets2mongo.MonoThread.java
void getNewTweets(GeoLocation myLoc, double radius) { try {//ww w .ja va 2 s. c om Query query = new Query(); Query.Unit unit = Query.KILOMETERS; // or Query.MILES; query.setGeoCode(myLoc, radius, unit); if (radius > 200) query.setCount(20000); else query.setCount(20000); QueryResult result; result = this.twitter.search(query); //System.out.println("Getting Tweets. by Geo.."); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { BasicDBObject basicObj = new BasicDBObject(); basicObj.put("user_Rname", tweet.getUser().getName()); basicObj.put("user_name", tweet.getUser().getScreenName()); basicObj.put("retweet_count", tweet.getRetweetCount()); basicObj.put("tweet_followers_count", tweet.getUser().getFollowersCount()); UserMentionEntity[] mentioned = tweet.getUserMentionEntities(); basicObj.put("tweet_mentioned_count", mentioned.length); basicObj.put("tweet_ID", tweet.getId()); basicObj.put("tweet_text", tweet.getText()); Status temp1 = tweet.getRetweetedStatus(); if (temp1 != null) basicObj.put("Re_tweet_ID", temp1.getUser().getId()); GeoLocation loc = tweet.getGeoLocation(); if (loc != null) { basicObj.put("Latitude", loc.getLatitude()); basicObj.put("Longitude", loc.getLongitude()); } basicObj.put("CreateTime", tweet.getCreatedAt()); basicObj.put("FavoriteCount", tweet.getFavoriteCount()); basicObj.put("user_Id", tweet.getUser().getId()); if (tweet.getUser().getTimeZone() != null) basicObj.put("UsertimeZone", tweet.getUser().getTimeZone()); if (tweet.getUser().getStatus() != null) basicObj.put("UserStatus", tweet.getUser().getStatus()); //basicObj.put("tweetLocation", tweet.getPlace().getGeometryCoordinates()); String U_Loc = tweet.getUser().getLocation(); if (U_Loc != null) basicObj.put("userLocation", U_Loc); basicObj.put("number_of_rt", tweet.getRetweetCount()); //basicObj.put("isRetweet", tweet.getPlace().getGeometryCoordinates()); //basicObj.put("POS", tweet.getWithheldInCountries()); if (mentioned.length > 0) { basicObj.append("mentions", pickMentions(mentioned)); } try { //items.insert(basicObj); collection.insert(basicObj); } catch (Exception e) { // System.out.println("MongoDB Connection Error : " + e.getMessage()); // loadMenu(); } } collection.ensureIndex(new BasicDBObject("tweet_ID", 1), new BasicDBObject("unique", true)); } catch (TwitterException ex) { java.util.logging.Logger.getLogger(MonoThread.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Data.Tweet.java
public Tweet(Status tweet) { this.author = tweet.getUser().getName(); this.message = tweet.getText(); }
From source file:DataCollection.ActiveTrendsStatusListener.java
@Override public void onStatus(Status arg0) { if (arg0.isRetweet()) return;/*from ww w .j a v a 2 s.com*/ ArrayList<Trend> trends = associatedStreamer.getActiveTrends(); Trend associatedTrend = null; for (int i = 0; i < trends.size(); i++) { if (arg0.toString().contains(trends.get(i).toString())) { associatedTrend = trends.get(i); break; } } if (associatedTrend == null) return; Tweet t = new Tweet(arg0.getText(), null, associatedTrend.toString(), arg0.getUser().getName(), new Date()); cache.addDatum(t); }
From source file:DataCollections.TweetHelper.java
public Tweet_dbo convertStatusToTweet_dbo(Status s) { Tweet_dbo tweet = new Tweet_dbo(); tweet.values[Tweet_dbo.map.get("tweet_id")].setValue(String.valueOf(s.getId())); tweet.values[Tweet_dbo.map.get("user_id")].setValue(String.valueOf(s.getUser().getId())); tweet.values[Tweet_dbo.map.get("user_screenname")] .setValue(removeEscapeCharacters(s.getUser().getScreenName())); if (s.getGeoLocation() != null) { tweet.values[Tweet_dbo.map.get("lon")].setValue(String.valueOf(s.getGeoLocation().getLongitude())); tweet.values[Tweet_dbo.map.get("lat")].setValue(String.valueOf(s.getGeoLocation().getLatitude())); }// w ww.j a va 2 s.com //tweet.values[Tweet_dbo.map.get("f_search")].setValue("true"); tweet.values[Tweet_dbo.map.get("text")].setValue(removeEscapeCharacters(s.getText())); tweet.values[Tweet_dbo.map.get("hashtags")].setValue(stringifyHashtags(s.getHashtagEntities())); tweet.values[Tweet_dbo.map.get("mentions")].setValue(stringiyMentions(s.getUserMentionEntities())); tweet.values[Tweet_dbo.map.get("favouritecount")].setValue(String.valueOf(s.getFavoriteCount())); tweet.values[Tweet_dbo.map.get("retweetcount")].setValue(String.valueOf(s.getRetweetCount())); return tweet; }
From source file:datasite.DataSite.java
public static void main(String[] args) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/*from ww w.j a v a2s . co m*/ cb.setOAuthConsumerKey("ConsumerKey"); cb.setOAuthConsumerSecret("ConsumerSecret"); cb.setOAuthAccessToken("AccessToken"); cb.setOAuthAccessTokenSecret("AccessTokenSecret"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener; 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(); try (PrintWriter out = new PrintWriter( new BufferedWriter(new FileWriter("tweet_input\\tweets.txt", true)))) { //out.println(username); String content = status.getText(); out.println(content + "\n"); //System.out.append( content +"\n"); } catch (IOException ex) { Logger.getLogger(DataSite.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[] = { "africa" }; fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); //twitterStream.(); }
From source file:datasite.SortedUnique.java
public static void main(String[] args) { ConfigurationBuilder confb = new ConfigurationBuilder(); confb.setDebugEnabled(true);/*from w ww. j a v a 2 s . c om*/ confb.setOAuthConsumerKey("Consumer Key"); confb.setOAuthConsumerSecret("Consumer Secret"); confb.setOAuthAccessToken("Access Token"); confb.setOAuthAccessTokenSecret("Access Token Secret"); TwitterStream twitterStream = new TwitterStreamFactory(confb.build()).getInstance(); StatusListener listener; 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) { PrintStream out = null; try { User user = status.getUser(); // gets Username String username = status.getUser().getScreenName(); String content = status.getText(); Set<String> userWrds = new HashSet<String>(); // HashSet implements Set Scanner sc = new Scanner(content + user); while (sc.hasNext()) { String word = sc.next(); userWrds.add(word); } out = new PrintStream(new FileOutputStream("tweet_output\\unique.txt", true)); Iterator<String> iter = userWrds.iterator(); for (int i = 1; i <= 1 && iter.hasNext(); i++) //System.out.println(iter.next()); out.println(userWrds.size()); } catch (FileNotFoundException ex) { Logger.getLogger(SortedUnique.class.getName()).log(Level.SEVERE, null, ex); } finally { out.close(); } } @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[] = { "africa" }; fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); //twitterStream.(); }
From source file:de.binfalse.jatter.processors.TwitterStatusProcessor.java
License:Open Source License
/** * Translate twitter status.//from w w w.j a va2 s .co m * * @param status * the status * @return the string */ public static String translateTwitterStatus(Status status) { String msg = ""; if (status.getUser() != null && status.getUser().getScreenName() != null) msg += "*" + status.getUser().getScreenName() + "*: "; if (!status.isRetweet()) msg += JatterTools.processTwitterMessag(status.getText()); msg += " [" + App.printDateFormat.format(status.getCreatedAt()); if (status.getGeoLocation() != null) msg += " - " + status.getGeoLocation().getLatitude() + "," + status.getGeoLocation().getLongitude(); msg += " - " + status.getId(); msg += "]"; if (status.isRetweet()) msg += "\n *RT* > " + translateTwitterStatus(status.getRetweetedStatus()); if (status.getQuotedStatus() != null) msg += "\n *QT* > " + translateTwitterStatus(status.getQuotedStatus()); return msg; }
From source file:de.hikinggrass.eiwomisarc.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * //from w w w . ja v a 2s . co m * @param args * message */ public UpdateStatus() { try { ConfigurationBuilder confBuilder = new ConfigurationBuilder(); //use https for oauth confBuilder.setUseSSL(true); Configuration conf = confBuilder.build(); Twitter twitter = new TwitterFactory(conf).getInstance(); twitter.setOAuthConsumer("HaBxuZMHygmtcuPeCbOLg", "zg6bV26ksBrgKHdhmiLlubTtV9MaDhoIRZC1ODUKw"); try { // get request token. // this will throw IllegalStateException if access token is already available RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Got request token."); System.out.println("Request token: " + requestToken.getToken()); System.out.println("Request token secret: " + requestToken.getTokenSecret()); AccessToken accessToken = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(requestToken); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } System.out.println("Got access token."); System.out.println("Access token: " + accessToken.getToken()); System.out.println("Access token secret: " + accessToken.getTokenSecret()); } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is not set. if (!twitter.getAuthorization().isEnabled()) { System.out.println("OAuth consumer key/secret is not set."); System.exit(-1); } } Status status = twitter.updateStatus("test from eiwomisarc"); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); System.exit(-1); } }
From source file:de.jetwick.tw.NewClass.java
License:Apache License
/** * A thread using the streaming API./*w w w . j av a 2s.c om*/ * Maximum tweets/sec == 50 !! we'll lose even infrequent tweets for a lot keywords! */ public Thread streaming(final String token, final String tokenSecret) { return new Thread() { StatusListener listener = new StatusListener() { int counter = 0; public void onStatus(Status status) { if (++counter % 20 == 0) log("async counter=" + counter); asyncMap.put(status.getId(), status.getText()); } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { log("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { log("Got track limitation notice:" + numberOfLimitedStatuses); } public void onScrubGeo(int userId, long upToStatusId) { log("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } public void onException(Exception ex) { ex.printStackTrace(); } }; public void run() { TwitterStream twitterStream = new TwitterStreamFactory() .getInstance(new AccessToken(token, tokenSecret)); twitterStream.addListener(listener); twitterStream.filter(new FilterQuery(0, null, new String[] { queryTerms }, null)); } }; }
From source file:de.jetwick.tw.TwitterSearch.java
License:Apache License
public static Twitter4JTweet toTweet(Status st, User user) { if (user == null) throw new IllegalArgumentException("User mustn't be null!"); if (st == null) throw new IllegalArgumentException("Status mustn't be null!"); Twitter4JTweet tw = new Twitter4JTweet(st.getId(), st.getText(), user.getScreenName()); tw.setCreatedAt(st.getCreatedAt());/* w w w. j a v a2s. co m*/ tw.setFromUser(user.getScreenName()); if (user.getProfileImageURL() != null) tw.setProfileImageUrl(user.getProfileImageURL().toString()); tw.setSource(st.getSource()); tw.setToUser(st.getInReplyToUserId(), st.getInReplyToScreenName()); tw.setInReplyToStatusId(st.getInReplyToStatusId()); if (st.getGeoLocation() != null) { tw.setGeoLocation(st.getGeoLocation()); tw.setLocation(st.getGeoLocation().getLatitude() + ", " + st.getGeoLocation().getLongitude()); } else if (st.getPlace() != null) tw.setLocation(st.getPlace().getCountryCode()); else if (user.getLocation() != null) tw.setLocation(toStandardLocation(user.getLocation())); return tw; }