List of usage examples for twitter4j Status getUser
User getUser();
From source file:edu.mum.cs.wap.TwitterUtil.java
private static String getTweetURL(Status status) { String url = "https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId(); return url;/* w w w. j a v a2 s. c o m*/ }
From source file:edu.uci.ics.asterix.external.util.TweetProcessor.java
License:Apache License
public AMutableRecord processNextTweet(Status tweet) { User user = tweet.getUser(); ((AMutableString) mutableUserFields[0]).setValue(getNormalizedString(user.getScreenName())); ((AMutableString) mutableUserFields[1]).setValue(getNormalizedString(user.getLang())); ((AMutableInt32) mutableUserFields[2]).setValue(user.getFriendsCount()); ((AMutableInt32) mutableUserFields[3]).setValue(user.getStatusesCount()); ((AMutableString) mutableUserFields[4]).setValue(getNormalizedString(user.getName())); ((AMutableInt32) mutableUserFields[5]).setValue(user.getFollowersCount()); ((AMutableString) mutableTweetFields[0]).setValue(tweet.getId() + ""); for (int i = 0; i < 6; i++) { ((AMutableRecord) mutableTweetFields[1]).setValueAtPos(i, mutableUserFields[i]); }//from w w w . ja va2 s . c o m if (tweet.getGeoLocation() != null) { ((AMutableDouble) mutableTweetFields[2]).setValue(tweet.getGeoLocation().getLatitude()); ((AMutableDouble) mutableTweetFields[3]).setValue(tweet.getGeoLocation().getLongitude()); } else { ((AMutableDouble) mutableTweetFields[2]).setValue(0); ((AMutableDouble) mutableTweetFields[3]).setValue(0); } ((AMutableString) mutableTweetFields[4]).setValue(getNormalizedString(tweet.getCreatedAt().toString())); ((AMutableString) mutableTweetFields[5]).setValue(getNormalizedString(tweet.getText())); for (int i = 0; i < 6; i++) { mutableRecord.setValueAtPos(i, mutableTweetFields[i]); } return mutableRecord; }
From source file:edu.ucsc.twitter.PeriodicTweetsSearch.java
License:Apache License
private static String getUserFirstname(long userID) { String result = "n/a"; while (Strings.same(result, "n/a")) { try {// w w w. j av a 2 s. com secondBreaker().callStarted(); try { final ResponseList<Status> status = TwitterEnvironment.getTwitterService() .getUserTimeline(userID); secondBreaker().callSucceeded(); if (!status.isEmpty()) { for (Status each : status) { final User user = each.getUser(); if (user == null) continue; final String firstname = user.getName(); final String screenname = user.getScreenName(); final boolean firstNameIsEmpty = Strings.isEmpty(firstname); final boolean screenmaeIsEmpty = Strings.isEmpty(screenname); if (firstNameIsEmpty && screenmaeIsEmpty) return "n/a"; if (firstNameIsEmpty && !screenmaeIsEmpty) return dealWithCamelCasing(screenname); if (screenmaeIsEmpty) return dealWithCamelCasing(firstname); return dealWithCamelCasing(firstname); } } else { return "none"; } } catch (Exception e) { secondBreaker().callFailed(new RuntimeException(e)); result = "n/a"; } } catch (Exception e) { result = "n/a"; } } return result; }
From source file:edu.umich.cse.pyongjoo.twittercrawl.GetUserTimeline.java
License:Apache License
/** * Usage: java twitter4j.examples.timeline.GetUserTimeline * * @param args String[]/* w w w .j av a2 s . c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { OAuthTokenReader oauth = new OAuthTokenReader("oauth_tokens.csv"); TwitterFactory tf = new TwitterFactory(oauth.getNextConfiguration()); // gets Twitter instance with default credentials Twitter twitter = tf.getInstance(); if (args.length < 2) { System.err.println("Usuage: command [username] [outputfile]"); System.exit(-1); } String filename = args[1]; FileWriter fstream = new FileWriter(filename, true); BufferedWriter out = new BufferedWriter(fstream); String user = ""; if (args.length >= 1) { user = args[0]; } // out.write("#document starts with username: " + user + "\n"); for (int i = 1; i <= 1; i++) { Paging pagingOption = new Paging(i, 200); try { List<Status> statuses; statuses = twitter.getUserTimeline(user, pagingOption); System.out.println("My Custom Showing @" + user + "'s user timeline."); for (Status status : statuses) { out.write(status.toString() + '\n'); System.out.println(status.getUser().getScreenName() + "tweets written."); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); // close the file out.close(); // output.close(); System.exit(-1); } } // close the file out.close(); // output.close(); }
From source file:edu.uml.TwitterDataMining.TwitterConsumer.java
/** * Save the results that we got from queryTwitter method This will append to * a file if it already exists//from w w w . jav a 2 s .c om * * @param tweets * @param filePath */ public static void saveResults(List<Status> tweets, String filePath) { try (FileWriter fw = new FileWriter(filePath, true)) { // try with resources (will close file pointers) for (Status tweet : tweets) { fw.write("@" + tweet.getUser().getScreenName() + "\t" + tweet.getText() + "\n"); } } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:entities.TwitterFeed.java
public void initTimeline() { timelineFrame = new JFrame("@SIM_IST Timeline"); timelineFrame.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); timelineBack = new JButton("Back"); timelineBack.addActionListener(this); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5;//ww w .jav a 2s.c o m c.gridx = 1; c.gridy = 1; c.gridwidth = 1; timelineFrame.add(timelineBack, c); timelineTweets = new JTextArea(); Font font = new Font("Gotham Narrow", Font.BOLD, 12); timelineTweets.setFont(font); timelineTweets.setEditable(false); timelineScrollPane = new JScrollPane(timelineTweets); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.ipady = 200; c.gridx = 0; c.gridy = 0; c.gridwidth = 3; timelineFrame.add(timelineScrollPane, c); KeyReader keys = new KeyReader(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(keys.getConsumerKey()) .setOAuthConsumerSecret(keys.getConsumerSecret()).setOAuthAccessToken(keys.getAccessToken()) .setOAuthAccessTokenSecret(keys.getAccessTokenSecret()); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { System.out.println("timeline retreval worked"); List<Status> statuses = twitter.getHomeTimeline(); for (Status status : statuses) { timelineTweets .append("@" + status.getUser().getScreenName() + " : " + status.getText() + "\n" + "\n"); timelineTweets.setLineWrap(true); timelineTweets.setWrapStyleWord(true); timelineTweets.setCaretPosition(0); System.out.println("@" + status.getUser().getName() + " : " + status.getText()); } } catch (TwitterException te) { System.out.print("timeline retreval failed"); te.printStackTrace(); } timelineFrame.pack(); timelineFrame.setSize(600, 300); timelineFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); timelineFrame.setLocationRelativeTo(null); timelineFrame.setVisible(true); }
From source file:es.portizsan.twitrector.tasks.TweetSearchTask.java
License:Open Source License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) { long before = System.currentTimeMillis() - (1000 * 60 * 15); try {/*from ww w . j a v a 2s .c o m*/ List<Twitrector> trl = new TwitrectorService().getTwitrectors(); if (trl == null || trl.isEmpty()) { logger.log(Level.WARNING, "No Twitrectors found!!!!!"); return; } for (Twitrector tr : trl) { logger.info("Searching for :" + tr.getQuery()); String search = tr.getQuery(); Twitter twitter = new TwitterService().getTwitterInstance(); Query query = new Query(search); query.setLocale("es"); query.setCount(100); if (tr.getLocation() != null) { GeoLocation location = new GeoLocation(tr.getLocation().getLatitude(), tr.getLocation().getLongitude()); Unit unit = Unit.valueOf(tr.getLocation().getUnit().name()); query.setGeoCode(location, tr.getLocation().getRadius(), unit); } QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { if (tweet.getCreatedAt().getTime() < before) continue; Queue queue = QueueFactory.getQueue("default"); queue.add(TaskOptions.Builder.withUrl("/tasks/tweetReply") .param("statusId", String.valueOf(tweet.getId())) .param("message", "@" + tweet.getUser().getScreenName() + " " + String.valueOf(tr.getResponse()))); logger.info("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); } } while ((query = result.nextQuery()) != null); } } catch (TwitterException te) { logger.log(Level.WARNING, "Failed to search tweets: ", te); } }
From source file:es.upm.oeg.entity.extractor.extractor.gate.TwitterCorpus.java
public void createCorpus() { repository = new FarolasRepo(); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();/*from w w w. j a v a2 s .c o m*/ try { corpus = Factory.newCorpus("tweetcorpus"); Query query = new Query(queryString); //"oddfarolas" QueryResult result; result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { Document doc = Factory.newDocument(tweet.getText()); doc.setName(String.valueOf(tweet.getId())); corpus.add(doc); logger.info(tweet.getId() + " @" + tweet.getUser().getScreenName() + " - " + tweet.getText() + " -" + tweet.getGeoLocation()); repository.instanciateNew(String.valueOf(tweet.getId()), tweet.getUser().getScreenName(), tweet.getText(), tweet.getGeoLocation()); } } catch (TwitterException te) { logger.error(te); logger.error("Failed to search tweets: " + te.getMessage()); System.exit(-1); } catch (ResourceInstantiationException ex) { logger.error(ex); } logger.info("corpus size" + corpus.size()); }
From source file:examencodrecu.MetodosTwitter.java
public void verLineaTiempo() throws TwitterException { List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing home timeline."); for (Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); }/* w ww .j av a 2 s . c o m*/ }
From source file:examencodrecu.MetodosTwitter.java
public void buscarTuit(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()); }// w ww. j av a 2 s . c om }