List of usage examples for twitter4j QueryResult nextQuery
Query nextQuery();
From source file:wise.TwitterUtils.java
public ArrayList<CheckinObject> dataList(String cityCode, String selectedDate, String maxTweetParam, String topTweetParam) throws IOException, JSONException, ParseException { ArrayList<CheckinObject> checkinList = new ArrayList<>(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(Constants.CONSUMER_KEY) .setOAuthConsumerSecret(Constants.CONSUMER_SECRET).setOAuthAccessToken(Constants.TOKEN) .setOAuthAccessTokenSecret(Constants.TOKEN_SECRET); Integer maxTweet = Integer.parseInt(maxTweetParam); Integer topTweet = Integer.parseInt(topTweetParam); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();// w w w .j a va 2s . c om DateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH); Date startDate = format.parse(selectedDate); Calendar c = Calendar.getInstance(); c.setTime(startDate); c.add(Calendar.DATE, 1); Date endDate = c.getTime(); Query query = SetQueryString(cityCode, startDate, endDate); QueryResult result = null; try { while (query != null && checkinList.size() <= maxTweet) { result = twitter.search(query); if (result != null) { for (Status status : result.getTweets()) { for (URLEntity urlEntity : status.getURLEntities()) { String urlCheckinId = urlEntity.getExpandedURL() .substring(urlEntity.getExpandedURL().lastIndexOf("/") + 1); GeoLocation geo = status.getGeoLocation(); CheckinObject checkin = new CheckinObject(); checkin.CheckinId = urlCheckinId; checkin.Count = 1;//status.getRetweetCount() + status.getFavoriteCount() + 1; checkin.Latitude = geo.getLatitude(); checkin.Longitude = geo.getLongitude(); if (!checkin.containsSameCoordinates(checkinList, checkin.Latitude, checkin.Longitude)) { checkinList.add(checkin); } else { int indexOfCheckinId = checkin.getIndexByCoordinates(checkinList, checkin.Latitude, checkin.Longitude); checkinList.get(indexOfCheckinId).setCheckinCount(checkin.Count); checkinList.get(indexOfCheckinId).setReplacementCheckinId(checkin.CheckinId); } } } query = result.nextQuery(); } else { query = null; } } } catch (TwitterException e) { } Collections.sort(checkinList, new CountComparator()); if (checkinList.size() > topTweet) { checkinList.subList(topTweet, checkinList.size()).clear(); // get top x } FourSquareCheckin fsq = new FourSquareCheckin(); for (CheckinObject checkin : checkinList) { fsq = getVenueInfo(checkin); checkin.LocationName = fsq.VenueName; checkin.Image = fsq.VenueImage; } return checkinList; }