List of usage examples for twitter4j Trend getQuery
String getQuery();
From source file:com.mmiagency.knime.nodes.twitter.util.TrendRow.java
License:Open Source License
private static DataCell[] createCells(final Location location, final Trend trend) { List<DataCell> cells = new ArrayList<DataCell>(); if (location.getCountryName() == null) { cells.add(new StringCell(location.getName())); } else {/* ww w. j a v a2 s . co m*/ cells.add(new StringCell(location.getCountryName() + " - " + location.getName())); } cells.add(new StringCell(trend.getName())); cells.add(new StringCell(trend.getQuery())); cells.add(new StringCell(trend.getURL())); return cells.toArray(new DataCell[cells.size()]); }
From source file:org.jwebsocket.plugins.twitter.TwitterPlugIn.java
License:Apache License
private void getTrends(WebSocketConnector aConnector, Token aToken) { TokenServer lServer = getServer();/*from w w w . j a va 2s. c om*/ // instantiate response token Token lResponse = lServer.createResponse(aToken); String lMsg; try { if (mLog.isDebugEnabled()) { mLog.debug("Retreiving trends..."); } if (!mCheckAuth(lResponse)) { mLog.error(lResponse.getString("msg")); } else { // return the list of messages as an array of strings... Map<String, List<String>> lAsOf = new FastMap<String, List<String>>(); List<String> lMessages; ResponseList lTrendList = mTwitter.getDailyTrends(); for (int lIdx = 0; lIdx < lTrendList.size(); lIdx++) { lMessages = new FastList<String>(); Trends lTrends = (Trends) lTrendList.get(lIdx); Trend[] lTrendArray = lTrends.getTrends(); for (Trend lTrend : lTrendArray) { lMessages.add(lTrend.getName() + ": " + lTrend.getQuery() + ", URL: " + lTrend.getUrl()); } lAsOf.put(Tools.DateToISO8601(lTrends.getTrendAt()), lMessages); } lResponse.setMap("messages", lAsOf); if (mLog.isInfoEnabled()) { mLog.info("Trends successfully received"); } } } catch (Exception lEx) { lMsg = lEx.getClass().getSimpleName() + ": " + lEx.getMessage(); mLog.error(lMsg); lResponse.setInteger("code", -1); lResponse.setString("msg", lMsg); } // send response to requester lServer.sendToken(aConnector, lResponse); }
From source file:twittersentimentanalysis.TwitterSentimentAnalysis.java
private static ArrayList<Tweet> getAllTweets(Twitter twitter) { logger.info("getAllTweets"); List<Status> listTweets = null; ArrayList<Tweet> listOfTweets = new ArrayList<Tweet>(); try {//from w w w .java 2 s .c o m Trends trends = twitter.getPlaceTrends(23424977); // System.out.println(trends.getLocation()); Trend trend[] = trends.getTrends(); logger.info("Number of Trends : " + trend.length); for (Trend trendTemp : trend) { //System.out.println("Name = " + trendTemp.getName()); //System.out.println("***************"); Query query = new Query(trendTemp.getQuery()); query.setCount(100); QueryResult queryResult = twitter.search(query); listTweets = queryResult.getTweets(); StanfordCoreNLPTool.init(); for (Status status : listTweets) { //System.out.println(status.getText()); Tweet tweet = getTweetObject(status); if (tweet != null) { tweet.setTrend(trendTemp.getName()); listOfTweets.add(tweet); } } } } catch (TwitterException ex) { Logger.getLogger(TwitterSentimentAnalysis.class.getName()).log(Level.SEVERE, null, ex); logger.info(ex.getMessage()); } return listOfTweets; }