List of usage examples for twitter4j Query setSinceId
public void setSinceId(long sinceId)
From source file:org.tweetalib.android.TwitterUtil.java
License:Apache License
public static Query updateQueryWithPaging(Query query, Paging paging) { if (paging.getMaxId() > -1) { query.setMaxId(paging.getMaxId()); }//www .j ava2s . c o m if (paging.getSinceId() > -1) { query.setSinceId(paging.getSinceId()); } /* * if (paging.getPage() != 1 && paging.getPage() != -1) { * query.setPage(paging.getPage()); } */ return query; }
From source file:org.xmlsh.twitter.search.java
License:BSD License
@Override public int run(List<XValue> args) throws Exception { Options opts = new Options(sCOMMON_OPTS + ",q=query:,geo=geocode:,lang:,locale:,t=result_type:,until:,since_id:,max_id:,include_entities:,sanitize", SerializeOpts.getOptionDefs()); opts.parse(args);/*from w ww . j av a2 s. c o m*/ mSerializeOpts = this.getSerializeOpts(opts); final boolean bSanitize = opts.hasOpt("sanitize"); args = opts.getRemainingArgs(); try { Twitter twitter = new TwitterFactory().getInstance(); Query query = new Query(); if (opts.hasOpt("query")) query.setQuery(opts.getOptStringRequired("query")); if (opts.hasOpt("lang")) query.setLang(opts.getOptStringRequired("lang")); if (opts.hasOpt("locale")) query.setLocale(opts.getOptStringRequired("locale")); if (opts.hasOpt("result_type")) query.setResultType(opts.getOptStringRequired("result_type")); if (opts.hasOpt("until")) query.setUntil(opts.getOptStringRequired("until")); if (opts.hasOpt("since_id")) query.setSinceId(opts.getOptValue("since_id").toLong()); if (opts.hasOpt("since")) query.setUntil(opts.getOptStringRequired("since")); if (opts.hasOpt("max_id")) query.setSinceId(opts.getOptValue("max_id").toLong()); QueryResult result = twitter.search(query); List<Status> tweets = result.getTweets(); OutputPort out = this.getStdout(); mWriter = new TwitterWriter(out.asXMLStreamWriter(mSerializeOpts), bSanitize); mWriter.startDocument(); mWriter.startElement("twitter"); mWriter.writeDefaultNamespace(); for (Status t : tweets) mWriter.write(t); mWriter.endElement(); mWriter.endDocument(); mWriter.closeWriter(); out.release(); } finally { } return 0; }
From source file:uk.ac.susx.tag.method51.twitter.params.QueryParams.java
License:Apache License
public Query buildQuery() throws SQLException { List<String> keywords = getKeywords(); if (keywords.size() == 0 && getLocation().size() == 0) { throw new RuntimeException("No keywords or locations provided"); }/*from w ww. j a v a2s . c o m*/ final String q; if (keywords.size() > 1) { q = "\"" + StringUtils.join(keywords, "\" OR \"") + "\""; } else { q = keywords.get(0); } //LOG.info("Searching keywords: {}", q); //LOG.info("Query length: {}", q.length()); Query query = new Query(q); query.setCount(100); query.setResultType(Query.RECENT); if (getAcceptedLanguages().size() > 0) { query.setLang(StringUtils.join(getAcceptedLanguages(), ",")); } if (getUntilId() != null) { query.setMaxId(getUntilId()); } if (getSinceId() != null) { query.setSinceId(getSinceId()); } else if (getSinceMaxId()) { try (Connection con = dbParams.get().buildConnection()) { long maxId = Util.getMaxID(con, getMysqlTweetOutputTable()); query.setSinceId(maxId); LOG.info("Determined {} as max id, searching since that.", maxId); } } if (getSinceId() == null && getSinceDate() != null) { long approxSinceId = Util.getMinSnowflakeId(getSinceDate()); query.setSinceId(approxSinceId); LOG.info("Determined min Snowflake ID {}", approxSinceId); } if (getUntilId() == null && getUntilDate() != null) { long approxUntilId = Util.getMaxSnowflakeId(getUntilDate()); query.setMaxId(approxUntilId); LOG.info("Determined max Snowflake ID {}", approxUntilId); } if (getLocation().size() == 1) { try { String[] geo = getLocation().get(0).split("\\|"); query.setGeoCode(new GeoLocation(Double.parseDouble(geo[0]), Double.parseDouble(geo[1])), Double.parseDouble(geo[2]), Query.KILOMETERS); } catch (NumberFormatException e) { throw new IllegalArgumentException("invalid location param " + getLocation().get(0), e); } } return query; }
From source file:webServices.RestServiceImpl.java
@GET @Path("/findTwittsRest") @Produces({ MediaType.TEXT_PLAIN })/* ww w . j av a 2 s. c o m*/ public String twitterSearchRest(@QueryParam("keys") String searchKeys, @QueryParam("sinceId") long sinceId, @QueryParam("maxId") long maxId, @QueryParam("update") boolean update, @QueryParam("location") String location) { final Vector<String> results = new Vector<String>(); String output = ""; long higherStatusId = Long.MIN_VALUE; long lowerStatusId = Long.MAX_VALUE; Query searchQuery = new Query(searchKeys); searchQuery.setCount(50); searchQuery.setResultType(Query.ResultType.recent); if (sinceId != 0) { if (update) { searchQuery.setSinceId(sinceId); } higherStatusId = sinceId; } if (maxId != 0) { if (!update) { searchQuery.setMaxId(maxId); } lowerStatusId = maxId; } if (location != null) { double lat = Double.parseDouble(location.substring(0, location.indexOf(","))); double lon = Double.parseDouble(location.substring(location.indexOf(",") + 1, location.length())); searchQuery.setGeoCode(new GeoLocation(lat, lon), 10, Query.KILOMETERS); } try { QueryResult qResult = twitter.search(searchQuery); for (Status status : qResult.getTweets()) { //System.out.println(Long.toString(status.getId())+" *** "+Long.toString(status.getUser().getId())+" *** "+status.isRetweet()+" *** "+status.isRetweeted()); higherStatusId = Math.max(status.getId(), higherStatusId); lowerStatusId = Math.min(status.getId(), lowerStatusId); if (!status.isRetweet()) { if (status.getGeoLocation() != null) { System.out.println(Long.toString(status.getId()) + "@" + Double.toString(status.getGeoLocation().getLatitude()) + "," + Double.toString(status.getGeoLocation().getLongitude())); results.add(Long.toString(status.getId()) + "@" + Double.toString(status.getGeoLocation().getLatitude()) + "," + Double.toString(status.getGeoLocation().getLongitude())); } else { results.add(Long.toString(status.getId()) + "@null"); } } } } catch (TwitterException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } TwitterResults resultsObj = new TwitterResults(results.toString(), higherStatusId, lowerStatusId); ObjectMapper mapper = new ObjectMapper(); try { output = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(resultsObj); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return output; }
From source file:wise.TwitterUtils.java
public static Query SetQueryString(String place, Date since, Date until) { Query query = new Query("place:" + place + "url:swarmapp.com"); String startDate = new SimpleDateFormat("yyyy-MM-dd").format(since); String endDate = new SimpleDateFormat("yyyy-MM-dd").format(until); query.setCount(100);// www .j a v a 2s . c o m query.setSince(startDate); query.setUntil(endDate); query.setSinceId(0); return query; }