List of usage examples for twitter4j Trends getTrends
Trend[] getTrends();
From source file:com.quicklookbusy.twending.TwendsRequest.java
License:Apache License
/** * Makes the request and calls the callback with the acquired data *///w w w . j a v a2 s. co m public void run() { ArrayList<String> topics = new ArrayList<String>(); Twitter twitter = new TwitterFactory().getInstance(); Trends usTrends; try { usTrends = twitter.getLocationTrends(23424977); for (int i = 0; i < usTrends.getTrends().length; i++) { topics.add(usTrends.getTrends()[i].getName()); } DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss d MMM"); Calendar cal = Calendar.getInstance(); topics.add("Last updated at " + dateFormat.format(cal.getTime())); } catch (TwitterException e) { e.printStackTrace(); } callback.doOnResult(topics); }
From source file:com.twitstreet.twitter.TwitterProxyImpl.java
License:Open Source License
@Override public Set<String> getTrends() { Set<String> trendSet = new HashSet<String>(); int i = 0;/*from w ww . j av a 2 s .c o m*/ for (String location : woiedMap.keySet()) { if (i > 0 && configMgr.isDev()) { break; } int woied = woiedMap.get(location); try { Trends ts = twitter.getLocationTrends(woied); if (ts != null) { Trend[] trends = ts.getTrends(); if (trends != null) { logger.debug("Location: " + location + ", trend size: " + trends.length); for (Trend trend : trends) { trendSet.add(trend.getName()); } } } } catch (TwitterException e) { e.printStackTrace(); } i++; } return trendSet; }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues[] makeTrendsContentValues(final List<Trends> trendsList) { if (trendsList == null) return new ContentValues[0]; final List<ContentValues> resultList = new ArrayList<>(); for (final Trends trends : trendsList) { if (trends == null) { continue; }/*from w w w. j a va2 s .c o m*/ final long timestamp = trends.getTrendAt().getTime(); for (final Trend trend : trends.getTrends()) { final ContentValues values = new ContentValues(); values.put(CachedTrends.NAME, trend.getName()); values.put(CachedTrends.TIMESTAMP, timestamp); resultList.add(values); } } return resultList.toArray(new ContentValues[resultList.size()]); }
From source file:edu.mum.cs.wap.TwitterUtil.java
private static List<Trend> getPlacedTrends(int woeid) throws TwitterException { Trends trends = twitter.getPlaceTrends(woeid); return Arrays.stream(trends.getTrends()) .map(t -> new Trend(t.getName(), TwitterUtil.buildTrendsURL(t.getName()))).limit(5) .collect(toList());// www . j ava2 s . c o m }
From source file:kerguelenpetrel.BotherSomeoneServlet.java
License:Apache License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { StringBuilder builder = new StringBuilder(); long[] friendIDs, victimIDs; resp.setContentType("text/plain; charset=UTF-8"); try {//from w w w . j av a2s . c om //Get the Twitter object Twitter twit = TwitterFactory.getSingleton(); //Find a friend of a follower to bother friendIDs = twit.getFollowersIDs(twit.getId(), cursor).getIDs(); if (friendIDs.length == 0) { resp.getWriter().println("Cannot find any followers to bother \n"); return; } //Load the potential victim IDs victimIDs = twit.getFollowersIDs(friendIDs[r.nextInt(friendIDs.length)], cursor).getIDs(); if (victimIDs.length == 0) { resp.getWriter().println("Cannot find any followers to bother \n"); return; } //Write to our victim String victim = twit.showUser(victimIDs[r.nextInt(victimIDs.length)]).getScreenName(); //Get a global trend Trends t = twit.getPlaceTrends(1); String trend = t.getTrends()[r.nextInt(t.getTrends().length)].getName(); builder.append(getWordnikContent(victim, trend, resp)); if (builder.length() > 280) builder.setLength(280); //Tweets are limited to 280 characters //Set the status StatusUpdate status = new StatusUpdate(builder.toString()); //Post the status twit.updateStatus(status); resp.getWriter().println("Tweet posted: " + status.getStatus()); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter \n"); e.printStackTrace(resp.getWriter()); } }
From source file:ontoSentiment.Busca.java
public void buscarPorTrendingTopics(String location, String lang) throws TwitterException { int totalTweets = 0; long maxID = -1; Trends trends = buscarTrendingTopics(location); for (int i = 0; i < trends.getTrends().length; i++) { System.out.println("\n" + trends.getTrends()[i].getName()); // Query q = new Query(trends.getTrends()[i].getName()); // q.setCount(Util.TWEETS_PER_QUERY); // q.resultType(Query.ResultType.recent); // q.setLang(lang); ///* www .ja va 2 s.com*/ // QueryResult r = Util.getTwitter().search(q); // // for (Status s : r.getTweets()) { // totalTweets++; // if (maxID == -1 || s.getId() < maxID) { // maxID = s.getId(); // } // // System.out.printf("s %s, @%-20s disse: %s\n", s.getCreatedAt().toString(), s.getUser().getScreenName(), Util.cleanText(s.getText())); // } } System.out.printf("\n\n Um total de %d tweets foram encontrados\n", totalTweets); }
From source file:org.apache.camel.component.twitter.util.TwitterConverter.java
License:Apache License
@Converter public static String toString(Trends trends) throws ParseException { StringBuilder s = new StringBuilder(); s.append("(" + trends.getTrendAt().toString() + ") "); boolean first = true; for (Trend trend : trends.getTrends()) { if (first) { first = false;/*w ww. j a v a2 s . co m*/ } else { s.append(","); } s.append(toString(trend)); } return s.toString(); }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
public Vertex trend(Network network) throws TwitterException { Trends trends = getConnection().getPlaceTrends(1); if (trends.getTrends().length > 0) { return network.createObject(trends.getTrends()[0].getName()); }/*from ww w. jav a 2 s . com*/ return null; }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues[] createTrends(final List<Trends> trendsList) { if (trendsList == null) return new ContentValues[0]; final List<ContentValues> resultList = new ArrayList<>(); for (final Trends trends : trendsList) { final long timestamp = trends.getTrendAt().getTime(); for (final Trend trend : trends.getTrends()) { final ContentValues values = new ContentValues(); values.put(CachedTrends.NAME, trend.getName()); values.put(CachedTrends.TIMESTAMP, timestamp); resultList.add(values);/*from w ww .j a va2 s.c o m*/ } } return resultList.toArray(new ContentValues[resultList.size()]); }
From source file:org.jwebsocket.plugins.twitter.TwitterPlugIn.java
License:Apache License
private void getTrends(WebSocketConnector aConnector, Token aToken) { TokenServer lServer = getServer();/* ww w .j av a 2 s . co m*/ // 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); }