List of usage examples for twitter4j Status getUser
User getUser();
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:pulltweets.PullTweets.java
private void printStatus(Status status) { System.out.println("@" + status.getUser().getScreenName()); System.out.println(status.getText()); System.out.println(""); }
From source file:reo7sp.socn.social.TwitterManager.java
License:Apache License
private void startListener() { new Thread("Twitter-Listener") { @Override//from w w w .j av a2 s .c om public void run() { try { while (!isInterrupted()) { Thread.sleep(75000); try { Status status = twitter.getMentionsTimeline().get(0); if (status.getId() != lastMentionID) { if (lastMentionID != 0) { UiModule.getInstance().notify(TwitterManager.this, status.getUser().getName() + ": " + status.getText()); } lastMentionID = status.getId(); saveSettings(); } connected = true; } catch (Exception err) { if (connected) { Log.e("TwitterManager", "Error in twitter listener. Trying to reconnect", err); } else { Log.e("TwitterManager", "Error in twitter listener. Trying to reconnect. " + err); } connected = false; } } } catch (InterruptedException ignored) { } } }.start(); }
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 . ja va2 s . c o m*/ * @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:rtb.PopularTweetCollector.java
License:Apache License
private String getTweetURL(Status status) { return "https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId(); }
From source file:samples.TwitterSentiment.java
private static String[] get_twits(Date tempdate, String querystr) { ArrayList<String> res = new ArrayList<String>(); try {/*from www . j a v a 2s . c om*/ twitter4j.Twitter twitter = getTwitter(); Query query = new Query(querystr); query.setCount(5000); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { //System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); res.add("@" + status.getUser().getScreenName() + ":" + status.getText()); } } catch (TwitterException ex) { Logger.getLogger(TwitterSentiment.class.getName()).log(Level.SEVERE, null, ex); } return res.toArray(new String[] {}); }
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 .j a v a2 s . 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(); } }
From source file:sentinets.ImportTweets.java
License:Open Source License
public void importTweetsAsCSV(String queryStr, int countOfTweets, String fileName) { /*Twitter twitter = new TwitterFactory().getInstance(); AccessToken accessToken = new AccessToken(ImportTweets.accessToken, ImportTweets.accessTokenSecret); /* ww w . j a v a 2s . c o m*/ twitter.setOAuthConsumer(ImportTweets.consumerKey, ImportTweets.consumerSecret); twitter.setOAuthAccessToken(accessToken);*/ CSVWriter cw = null; try { cw = new CSVWriter(new FileWriter(fileName), '\t', '\"', '\\'); String header = "c_emo\tc_hash\tm_mention\turl\tc_url\ttweet_text\tc_mention" + "\tparsed_text\tlength\tm_emo\tuser\tpublished_date\tc_quote" + "\tm_hash\te/p/i\ts/ns/na"; cw.writeNext(header.split("\t")); ParseTweet pt; for (Status tweet : this.getTweets(queryStr, countOfTweets)) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); pt = new ParseTweet(tweet); //stats.updateStatistics(pt); //pt.showFeatures(); cw.writeNext(this.getRowAsList(pt)); } cw.close(); //stats.printStats(new PrintStream(new File(fileName+".stats.tsv"))); } catch (IOException e) { e.printStackTrace(); } }
From source file:sentinets.ParseTweet.java
License:Open Source License
public ParseTweet(Status tweet) { this(tweet.getText()); this.tweet = tweet; this.url = "http://twitter.com/" + tweet.getUser().getScreenName() + "/status/" + tweet.getId(); this.user = tweet.getUser().getScreenName(); this.published_date = tweet.getCreatedAt().toString(); }
From source file:Situational_Awareness.TwitterSearch.java
public ArrayList<Information> twitterFeed(String twitterURL) { ArrayList<Information> informationList = new ArrayList<>(); try {//from w w w . j av a2 s . c om Query query = new Query(twitterURL); QueryResult result; result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); Date tweeted = tweet.getCreatedAt(); if (tweeted.getTime() >= java.lang.System.currentTimeMillis() - 36000000) { Information newInfo = new Information(tweet.getId(), tweet.getUser().getScreenName(), tweet.getText(), tweet.getUser().getLocation(), tweet.getUser().getProfileImageURL()); informationList.add(newInfo); } else { System.out.println("information not relevant"); } } } catch (Exception te) { System.out.println("Failed to search tweets: " + te.getMessage()); } return informationList; }