List of usage examples for twitter4j Status getUser
User getUser();
From source file:cc.twittertools.index.ExtractTweetidsFromCollection.java
License:Apache License
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); CommandLine cmdline = null;/* ww w . j a va2s . c o m*/ CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(COLLECTION_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractTweetidsFromCollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } StatusStream stream = new JsonStatusCorpusReader(file); Status status; while ((status = stream.next()) != null) { System.out.println(status.getId() + "\t" + status.getUser().getScreenName()); } }
From source file:cd.examentwitter.Metodos.java
/** * Metodo para visualizar todo el timeLine del usuario logueado *///from w w w. j a va 2 s. c o m public void timeLine() { try { List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Mostrando timeline"); for (Status status : statuses) { System.out.println(status.getUser().getName() + ": " + status.getText()); } } catch (TwitterException ex) { Logger.getLogger(Metodos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cd.examentwitter.Metodos.java
/** * Metodo para buscar una determinada secuencia caracteres por todo Twitter *///from w ww. jav a 2 s . co m public void search() { try { String search = JOptionPane.showInputDialog("Qu secuencia de caracteres desea buscar?"); QueryResult result = twitter.search(new Query(search)); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ": " + status.getText()); } } catch (TwitterException ex) { Logger.getLogger(Metodos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ch.schrimpf.core.TwitterCrawler.java
License:Open Source License
/** * Performs a single crawl step according to the previous initialized query * until the specified limit is reached. Received tweets are stored in the * *.csv specified in the easyTwitterCrawler.properties file. * <p/>/* w w w . j av a 2s.c om*/ * TODO make selecting values flexible * * @param limit to stop on */ public void crwal(int limit) { LOG.info("receiving tweets..."); int i = 0; while (i < limit && running) { try { QueryResult res = twitter.search(query); if (res.getMaxId() > last) { for (Status status : res.getTweets()) { String[] line = { String.valueOf(status.getId()), String.valueOf(status.getCreatedAt()), status.getText(), String.valueOf(status.getUser()), String.valueOf(status.getPlace()), status.getLang() }; csv.writeResult(Arrays.asList(line)); i++; } last = res.getMaxId(); } else { break; } } catch (TwitterException e) { LOG.warning("could not process tweets"); } } tweets += i; LOG.info(i + " tweets received in this crawl"); LOG.info("totally " + tweets + " received"); }
From source file:clientetwitter.ClienteTwitter.java
public static void ReadTimeLine() throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("ZpF1TSpAyQlBLMN7egUz3uT3D") .setOAuthConsumerSecret("r2icg36QB6G862Re2IvwHNGuDK25z5awKSeNG9kV9LRpcAmuOW") .setOAuthAccessToken("4314010284-QGXKFbFQ5TK4zqbplRsfoP0wL6NTv7bsMJypWex") .setOAuthAccessTokenSecret("4v61YXTkzM3Kob0xAHu59ISgM0fTKSLrOuDXTG5ctX7rr"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); //reading// w ww .j av a2 s . c o m List<Status> statuses = tw.getHomeTimeline(); for (Status status1 : statuses) { System.out.println(status1.getUser().getName() + ": " + status1.getText()); } }
From source file:cloudcomputebot.MentionListener.java
License:Open Source License
@Override public void onStatus(Status status) { System.out.println(status.getUser().getScreenName() + ": " + status.getText()); try {/*from www . j a va 2s .co m*/ Decipher.handleInput(status, status.getUser()); } catch (IOException ex) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex); } catch (TwitterException ex) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Collector.TweetCollector.java
public static List<Status> printTimeLine(String account) { try {/*w w w . ja v a 2 s .co m*/ Query query = new Query(account); QueryResult result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); } return tweets; } catch (TwitterException te) { System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } return null; }
From source file:Collector.TweetCollector.java
public static void storeTweet(Status tweet) { BasicDBObject basicOBJ = new BasicDBObject(); 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()); basicOBJ.put("created_at", tweet.getCreatedAt()); try {//from w ww .ja va 2 s.co m items.insert(basicOBJ); } catch (Exception e) { System.out.println("Could not store Tweet please try again" + e.getMessage()); } }
From source file:collector.TwitterCollector.java
public LinkedHashSet<Tweet> search(String queryExpression, int maxResults) { Query query = new Query(queryExpression); int numberOfTweets = maxResults;//512; long lastID = Long.MAX_VALUE; query = query.lang("pt"); List<Status> tweets = new ArrayList<>(); boolean finish = false; while ((tweets.size() < numberOfTweets) && !finish) { System.out.print("."); if (numberOfTweets - tweets.size() > 100) {//100) { query.setCount(100);//100); } else {/* w ww . j a v a 2s . c om*/ query.setCount(numberOfTweets - tweets.size()); } try { QueryResult result = twitter.search(query); List<Status> resultList = result.getTweets(); if (resultList == null || resultList.isEmpty()) { finish = true; System.out.println("no foram encontrados mais tweets"); } else { tweets.addAll(resultList); for (Status t : tweets) { if (t.getId() < lastID) { lastID = t.getId(); } } } } catch (TwitterException ex) { System.err.println(ex.getMessage()); } query.setMaxId(lastID - 1); } LinkedHashSet<Tweet> out = new LinkedHashSet<>(); for (Status status : tweets) { if (!status.getText().startsWith("RT")) { TwitterUser user; user = new TwitterUser().addID(status.getUser().getId()).addName(status.getUser().getName()) .addLocation(status.getUser().getLocation()).addDateSignin(status.getUser().getCreatedAt()) .addCountTweets(status.getUser().getStatusesCount()) .addCountFavorites(status.getUser().getFavouritesCount()) .addCountFriends(status.getUser().getFriendsCount()) .addCountFollowers(status.getUser().getFollowersCount()); Tweet tweet = new Tweet().addUser(user).addText(status.getText()).addID(status.getId()) .addDate(status.getCreatedAt()) .addLatitude(status.getGeoLocation() != null ? status.getGeoLocation().getLatitude() : Double.MAX_VALUE) .addLongitude(status.getGeoLocation() != null ? status.getGeoLocation().getLongitude() : Double.MAX_VALUE); out.add(tweet); } } return out; }
From source file:collector.TwitterCollector.java
public LinkedHashSet<Tweet> userSearchData(String userName, int maxResults) { LinkedHashSet<Tweet> out = new LinkedHashSet<>(); Paging paging = new Paging(1, 180); int numberOfTweets = maxResults;//512; long lastID = Long.MAX_VALUE; ArrayList<Status> status = new ArrayList<>(); while (status.size() < numberOfTweets) { if (numberOfTweets - status.size() > 180) {//100) { paging.setCount(180);//100); } else {/*from ww w . ja v a 2s . com*/ paging.setCount(numberOfTweets - status.size()); } try { List<Status> timeLine = twitter.getUserTimeline(userName, paging); status.addAll(timeLine); for (Status t : status) { if (t.getId() < lastID) { lastID = t.getId(); } } } catch (TwitterException ex) { System.err.println(ex.getMessage()); } paging.setMaxId(lastID - 1); } //armazenar os atributos interessantes a analise dos tweets int qtdretweet = 0; for (Status sta : status) { String text = sta.getText(); if (!sta.isRetweet() && !sta.isRetweeted() && !text.startsWith("RT")) { //&& !TweetMediaDetect.detect(text)) { TwitterUser user; user = new TwitterUser().addID(sta.getUser().getId()).addName(sta.getUser().getName()) .addLocation(sta.getUser().getLocation()).addDateSignin(sta.getUser().getCreatedAt()) .addCountTweets(sta.getUser().getStatusesCount()) .addCountFavorites(sta.getUser().getFavouritesCount()) .addCountFriends(sta.getUser().getFriendsCount()) .addCountFollowers(sta.getUser().getFollowersCount()); Tweet tweet = new Tweet().addUser(user).addText(sta.getText()).addID(sta.getId()) .addDate(sta.getCreatedAt()) .addLatitude(sta.getGeoLocation() != null ? sta.getGeoLocation().getLatitude() : Double.MAX_VALUE) .addLongitude(sta.getGeoLocation() != null ? sta.getGeoLocation().getLongitude() : Double.MAX_VALUE); out.add(tweet); } else { qtdretweet++; } } return out; }