List of usage examples for twitter4j Query MIXED
ResultType MIXED
To view the source code for twitter4j Query MIXED.
Click Source Link
From source file:ai.ilikeplaces.logic.Listeners.ListenerMain.java
License:Open Source License
/** * @param request__/*from w w w . ja v a 2s . c om*/ * @param response__ */ @Override public void processRequest(final ItsNatServletRequest request__, final ItsNatServletResponse response__) { new AbstractListener(request__, response__) { protected String location; protected String superLocation; protected Long WOEID; /** * Initialize your document here by appending fragments */ @Override @SuppressWarnings("unchecked") @_todo(task = "If location is not available, it should be added through a w" + "id" + "get(or fragment maybe?)") protected final void init(final ItsNatHTMLDocument itsNatHTMLDocument__, final HTMLDocument hTMLDocument__, final ItsNatDocument itsNatDocument__, final Object... initArgs) { final SmartLogger sl = SmartLogger.start(Loggers.LEVEL.DEBUG, "Location Page.", 60000, null, true); //this.location = (String) request_.getServletRequest().getAttribute(RBGet.config.getString("HttpSessionAttr.location")); getLocationSuperLocation: { final String[] attr = ((String) request__.getServletRequest() .getAttribute(RBGet.globalConfig.getString(HTTP_SESSION_ATTR_LOCATION))).split("_"); location = attr[0]; if (attr.length == 3) { superLocation = attr[2]; } else { superLocation = EMPTY; } tryLocationId: { try { final String w = request__.getServletRequest().getParameter(Location.WOEID); if (w != null) { WOEID = Long.parseLong(request__.getServletRequest().getParameter(Location.WOEID)); } } catch (final NumberFormatException e) { Loggers.USER_EXCEPTION.error(WRONG_WOEID_FORMAT, e); } } } sl.appendToLogMSG(RETURNING_LOCATION + location + TO_USER); final ResourceBundle gUI = ResourceBundle.getBundle(AI_ILIKEPLACES_RBS_GUI); layoutNeededForAllPages: { setLoginWidget: { try { new SignInOn(request__, $(Main_login_widget), new SignInOnCriteria().setHumanId(new HumanId(getUsername())) .setSignInOnDisplayComponent( SignInOnCriteria.SignInOnDisplayComponent.MOMENTS)) { }; } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOGIN_WIDGET, t); } } SEO: { try { setMainTitle: { $(mainTitle).setTextContent( MessageFormat.format(gUI.getString("woeidpage.title"), location)); } setMetaDescription: { $(mainMetaDesc).setAttribute(MarkupTag.META.content(), MessageFormat.format(gUI.getString("woeidpage.desc"), location)); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SEO, t); } } signOnDisplayLink: { try { if (getUsername() != null) { $(Main_othersidebar_identity).setTextContent( gUI.getString(AI_ILIKEPLACES_LOGIC_LISTENERS_LISTENER_MAIN_0004) + getUsernameAsValid()); } else { $(Main_othersidebar_identity).setTextContent( gUI.getString(AI_ILIKEPLACES_LOGIC_LISTENERS_LISTENER_MAIN_0005) + location); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SIGN_ON_DISPLAY_LINK, t); } } setProfileLink: { try { if (getUsername() != null) { $(Main_othersidebar_profile_link).setAttribute(MarkupTag.A.href(), Controller.Page.Profile.getURL()); } else { $(Main_othersidebar_profile_link).setAttribute(MarkupTag.A.href(), Controller.Page.signup.getURL()); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_PROFILE_LINK, t); } } setProfilePhotoLink: { try { if (getUsername() != null) { /** * TODO check for db failure */ String url = DB.getHumanCRUDHumanLocal(true) .doDirtyRHumansProfilePhoto(new HumanId(getUsernameAsValid())) .returnValueBadly(); url = url == null ? null : RBGet.globalConfig.getString(PROFILE_PHOTOS) + url; if (url != null) { $(Main_profile_photo).setAttribute(MarkupTag.IMG.src(), url); //displayBlock($(Main_profile_photo)); } else { //displayNone($(Main_profile_photo)); } } else { //displayNone($(Main_profile_photo)); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_PROFILE_PHOTO_LINK, t); } } } final Return<Location> r; if (WOEID != null) { r = DB.getHumanCRUDLocationLocal(true).doRLocation(WOEID, REFRESH_SPEC); } else { r = new ReturnImpl<Location>(ExceptionCache.UNSUPPORTED_OPERATION_EXCEPTION, "Search Unavailable", false); //r = DB.getHumanCRUDLocationLocal(true).dirtyRLocation(location, superLocation); } if (r.returnStatus() == 0 && r.returnValue() != null) { final Location existingLocation_ = r.returnValue(); GEO: { if (existingLocation_.getLocationGeo1() == null || existingLocation_.getLocationGeo2() == null) { final Client ygpClient = YAHOO_GEO_PLANET_FACTORY .getInstance(RBGet.globalConfig.getString("where.yahooapis.com.v1.place")); final Place place = ygpClient.getPlace(existingLocation_.getLocationId().toString()); existingLocation_.setLocationGeo1(Double.toString(place.getCoordinates().getY())); existingLocation_.setLocationGeo2(Double.toString(place.getCoordinates().getX())); new Thread(new Runnable() { @Override public void run() { DB.getHumanCRUDLocationLocal(true).doULocationLatLng( new Obj<Long>(existingLocation_.getLocationId()), new Obj<Double>(place.getCoordinates().getY()), new Obj<Double>(place.getCoordinates().getX())); } }).run(); } } final Location locationSuperSet = existingLocation_.getLocationSuperSet(); GEO_WIDGET: { new ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Comment(request__, new CommentCriteria(), $(Controller.Page.Main_right_column)) { @Override protected void init(CommentCriteria commentCriteria) { final ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Place place = new ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Place( request__, new PlaceCriteria() //This Place .setPlaceNamePre("Exciting events in ") .setPlaceName(existingLocation_.getLocationName()) .setPlaceLat(existingLocation_.getLocationGeo1()) .setPlaceLng(existingLocation_.getLocationGeo2()) //Parent Place //.setPlaceSuperName(locationSuperSet.getLocationName()) //.setPlaceSuperLat(locationSuperSet.getLocationGeo1()) //.setPlaceSuperLng(locationSuperSet.getLocationGeo2()) //Parent WOEID //.setPlaceSuperWOEID(locationSuperSet.getWOEID().toString()) , $$(CommentIds.commentPerson)); place.$$displayNone(place.$$( ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Place.PlaceIds.placeWidget)); } }; } final List<String> titleManifest = new ArrayList<String>(); EVENTS_WIDGETS: { try { /* final JSONObject jsonObject = Modules.getModules().getYahooUplcomingFactory() .getInstance("http://upcoming.yahooapis.com/services/rest/") .get("", new HashMap<String, String>() { {//Don't worry, this is a static initializer of this map :) put("method", "event.search"); put("woeid", WOEID.toString()); put("format", "json"); } } ); final JSONArray events = jsonObject.getJSONObject("rsp").getJSONArray("event");*/ final JSONObject jsonObject = Modules.getModules().getEventulFactory() .getInstance("http://api.eventful.com/json/events/search/") .get("", new HashMap<String, String>() { {//Don't worry, this is a static initializer of this map :) put("location", "" + existingLocation_.getLocationGeo1() + "," + existingLocation_.getLocationGeo2()); put("within", "" + 100); } } ); Loggers.debug("Eventful Reply:" + jsonObject.toString()); // final String eventName = eventJSONObject.getString("title"); // final String eventUrl = eventJSONObject.getString("url"); // final String eventDate = eventJSONObject.getString("start_time"); // final String eventVenue = eventJSONObject.getString("venue_name"); final JSONArray events = jsonObject.getJSONObject("events").getJSONArray("event"); for (int i = 0; i < events.length(); i++) { final JSONObject eventJSONObject = new JSONObject(events.get(i).toString()); titleManifest.add(eventJSONObject.get("title").toString()); final String photoUrl; String temp = null; try { temp = eventJSONObject.getJSONObject("image").get("url").toString(); } catch (final Throwable e) { SmartLogger.g().l(e.getMessage()); } finally { photoUrl = temp; } //The pain I go through to make variables final :D new Event(request__, new EventCriteria() .setEventName(eventJSONObject.get("title").toString()) .setEventStartDate(eventJSONObject.get("start_time").toString()) .setEventPhoto(photoUrl) .setPlaceCriteria(new PlaceCriteria() .setPlaceNamePre("This event is taking place in ") .setPlaceName(existingLocation_.getLocationName()) .setPlaceLat(eventJSONObject.get("latitude").toString()) .setPlaceLng(eventJSONObject.get("longitude").toString()) //Parent Place .setPlaceSuperNamePre( existingLocation_.getLocationName() + " is located in ") .setPlaceSuperName(locationSuperSet.getLocationName()) .setPlaceSuperLat(locationSuperSet.getLocationGeo1()) .setPlaceSuperLng(locationSuperSet.getLocationGeo2()) //Parent WOEID .setPlaceSuperWOEID(locationSuperSet.getWOEID().toString()) ), $(Controller.Page.Main_right_column)); } } catch (final JSONException e) { sl.l("Error fetching data from Yahoo Upcoming: " + e.getMessage()); } } TWITTER_WIDGETS: { try { final Query _query = new Query( "fun OR happening OR enjoy OR nightclub OR restaurant OR party OR travel :)"); _query.geoCode( new GeoLocation(Double.parseDouble(existingLocation_.getLocationGeo1()), Double.parseDouble(existingLocation_.getLocationGeo2())), 40, Query.MILES); _query.setResultType(Query.MIXED); final QueryResult result = TWITTER.search(_query); //final QueryResult result = TWITTER.search(new Query("Happy").geoCode(new GeoLocation(Double.parseDouble(existingLocation_.getLocationGeo1()), Double.parseDouble(existingLocation_.getLocationGeo2())), 160, Query.MILES)); for (Status tweet : result.getTweets()) { new ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Person(request__, new PersonCriteria().setPersonName(tweet.getUser().getName()) .setPersonPhoto(tweet.getUser().getProfileImageURL()) .setPersonData(tweet.getText()), $(Main_right_column)); titleManifest.add(tweet.getText()); } if (result.getTweets().size() == 0) { sl.l("No twitter results found"); } } catch (final Throwable t) { sl.l("An error occurred during twitter fetch:" + t.getMessage()); } } SEO: { setMetaGEOData: { $(Main_ICBM).setAttribute(MarkupTag.META.content(), existingLocation_.getLocationGeo1() + COMMA + existingLocation_.getLocationGeo2()); $(Main_geoposition).setAttribute(MarkupTag.META.content(), existingLocation_.getLocationGeo1() + COMMA + existingLocation_.getLocationGeo2()); $(Main_geoplacename).setAttribute(MarkupTag.META.content(), existingLocation_.getLocationName()); $(Main_georegion).setAttribute(MarkupTag.META.content(), locationSuperSet.getLocationName()); } } setLocationIdForJSReference: { try { final Element hiddenLocationIdInputTag = $(INPUT); hiddenLocationIdInputTag.setAttribute(INPUT.type(), INPUT.typeValueHidden()); hiddenLocationIdInputTag.setAttribute(INPUT.id(), JSCodeToSend.LocationId); hiddenLocationIdInputTag.setAttribute(INPUT.value(), existingLocation_.getLocationId().toString()); hTMLDocument__.getBody().appendChild(hiddenLocationIdInputTag); $(Main_location_name).setAttribute(INPUT.value(), existingLocation_.getLocationName() + ""); $(Main_super_location_name).setAttribute(INPUT.value(), locationSuperSet.getLocationName() + ""); } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOCATION_ID_FOR_JSREFERENCE, t); } } setLocationNameForJSReference: { try { final Element hiddenLocationIdInputTag = $(INPUT); hiddenLocationIdInputTag.setAttribute(INPUT.type(), INPUT.typeValueHidden()); hiddenLocationIdInputTag.setAttribute(INPUT.id(), JSCodeToSend.LocationName); hiddenLocationIdInputTag.setAttribute(INPUT.value(), existingLocation_.getLocationName() + OF + locationSuperSet.getLocationName()); hTMLDocument__.getBody().appendChild(hiddenLocationIdInputTag); } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOCATION_NAME_FOR_JSREFERENCE, t); } } setLocationAsPageTopic: { try { final StringBuilder title = new StringBuilder(); for (final String titleGuest : titleManifest) { title.append(titleGuest); } final String finalTitle = title.toString(); $(Main_center_main_location_title).setTextContent(finalTitle.isEmpty() ? (THIS_IS + existingLocation_.getLocationName() + OF + locationSuperSet) : finalTitle); for (final Element element : generateLocationLinks(DB.getHumanCRUDLocationLocal(true) .doDirtyRLocationsBySuperLocation(existingLocation_))) { $(Main_location_list).appendChild(element); displayBlock($(Main_notice_sh)); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOCATION_AS_PAGE_TOPIC, t); } } } else { noSupportForNewLocations: { try { // $(Main_notice).appendChild(($(P).appendChild( // hTMLDocument__.createTextNode(RBGet.logMsgs.getString("CANT_FIND_LOCATION") // + " Were you looking for " // )))); // for (final Element element : generateLocationLinks(DB.getHumanCRUDLocationLocal(true).dirtyRLikeLocations(location))) { // $(Main_notice).appendChild(element); // displayBlock($(Main_notice_sh)); // } NotSupportingLikeSearchTooForNow: { $(Main_notice).appendChild(($(P).appendChild(hTMLDocument__ .createTextNode(RBGet.logMsgs.getString("CANT_FIND_LOCATION"))))); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_NO_SUPPORT_FOR_NEW_LOCATIONS, t); } } } sl.complete(Loggers.LEVEL.SERVER_STATUS, Loggers.DONE); } /** * Use ItsNatHTMLDocument variable stored in the AbstractListener class */ @Override protected void registerEventListeners(final ItsNatHTMLDocument itsNatHTMLDocument__, final HTMLDocument hTMLDocument__, final ItsNatDocument itsNatDocument__) { } private List<Element> generateLocationLinks(final List<Location> locationList) { final ElementComposer UList = ElementComposer.compose($(UL)).$ElementSetAttribute(MarkupTag.UL.id(), PLACE_LIST); for (Location location : locationList) { final Element link = $(A); link.setTextContent(TRAVEL_TO + location.getLocationName() + OF + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.href(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName() + Parameter.get(Location.WOEID, location.getWOEID().toString(), true)); link.setAttribute(A.alt(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.title(), CLICK_TO_EXPLORE + location.getLocationName() + OF + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.classs(), VTIP); final Element linkDiv = $(DIV); linkDiv.appendChild(link); UList.wrapThis(ElementComposer.compose($(LI)).wrapThis(linkDiv).get()); } final List<Element> elements = new ArrayList<Element>(); elements.add(UList.get()); return elements; } private Element generateLocationLink(final Location location) { final Element link = $(A); link.setTextContent(TRAVEL_TO + location.getLocationName() + OF + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.href(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName() + Parameter.get(Location.WOEID, location.getWOEID().toString(), true)); link.setAttribute(A.alt(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName()); return link; } private Element generateSimpleLocationLink(final Location location) { final Element link = $(A); link.setTextContent(location.getLocationName()); link.setAttribute(A.href(), PAGE + location.getLocationName() + Parameter.get(Location.WOEID, location.getWOEID().toString(), true)); link.setAttribute(A.alt(), PAGE + location.getLocationName()); return link; } };//Listener }
From source file:com.ontotext.s4.TwitterVisualization.downloadTweets.SearchTweets.java
License:Open Source License
/** * This method executes search query on Twitter. The results are saved into the preconfigured result folder. * @param queryString// w w w.j a v a2s. co m * the search query string. For more information refer to https://dev.twitter.com/docs/using-search * @throws TwitterException * any problem related to authentication, communication, search, etc. */ public void search(String queryString) throws TwitterException { // configures twitter API keys Twitter twitter = ConfigurateTwitterAccount(); // preparint the query Query query = new Query(queryString); // search in both popular and recent tweets query.resultType(Query.MIXED); // restrict result to English language query.lang("en"); // result of the query QueryResult result; do { logger.debug(query); // executing the query result = twitter.search(query); // collect all tweets available List<Status> tweets = result.getTweets(); // save each tweet into a file for (Status tweet : tweets) { saveTweetIntoFile(tweet); } } // handle the paging of the results while ((query = result.nextQuery()) != null); }
From source file:de.jetsli.twitter.TwitterSearch.java
License:Apache License
long search(String term, Collection<Status> result, Map<String, User> userMap, int tweets, long lastMaxCreateTime) throws TwitterException { long maxId = 0L; long maxMillis = 0L; // TODO it looks like only one page is possible with 4.0.0 int maxPages = 1; int hitsPerPage = tweets; boolean breakPaging = false; for (int page = 0; page < maxPages; page++) { Query query = new Query(term); // RECENT or POPULAR query.setResultType(Query.MIXED); // avoid that more recent results disturb our paging! if (page > 0) query.setMaxId(maxId);//from w ww . j ava 2s .c o m query.setCount(hitsPerPage); QueryResult res = twitter.search(query); // is res.getTweets() sorted? for (Status twe : res.getTweets()) { // determine maxId in the first page if (page == 0 && maxId < twe.getId()) maxId = twe.getId(); if (maxMillis < twe.getCreatedAt().getTime()) maxMillis = twe.getCreatedAt().getTime(); if (twe.getCreatedAt().getTime() + 1000 < lastMaxCreateTime) breakPaging = true; else { String userName = twe.getUser().getScreenName().toLowerCase(); User user = userMap.get(userName); if (user == null) userMap.put(userName, twe.getUser()); result.add(twe); } } // minMillis could force us to leave earlier than defined by maxPages // or if resulting tweets are less then request (but -10 because of twitter strangeness) if (breakPaging || res.getTweets().size() < hitsPerPage - 10) break; } return maxMillis; }
From source file:de.jetwick.tw.NewClass.java
License:Apache License
/** A thread using the search API */ public Thread search() { return new Thread() { @Override/*from w ww . ja v a 2 s .co m*/ public void run() { int MINUTES = 2; Twitter twitter = new TwitterFactory().getInstance(); try { while (!isInterrupted()) { Query query = new Query(queryTerms); // RECENT or POPULAR or MIXED // doesn't make a difference if MIXED or RECENT query.setResultType(Query.MIXED); query.setPage(1); query.setRpp(100); QueryResult res = twitter.search(query); for (Tweet tw : res.getTweets()) { searchMap.put(tw.getId(), tw.getText()); } Thread.sleep(MINUTES * 60 * 1000L); } } catch (Exception ex) { ex.printStackTrace(); } } }; }
From source file:de.jetwick.tw.TwitterSearch.java
License:Apache License
long search(String term, Collection<JTweet> result, Map<String, JUser> userMap, int tweets, long lastMaxCreateTime) throws TwitterException { long maxId = 0L; long maxMillis = 0L; int hitsPerPage; int maxPages; if (tweets < 100) { hitsPerPage = tweets;//w ww.j a va 2 s.c o m maxPages = 1; } else { hitsPerPage = 100; maxPages = tweets / hitsPerPage; if (tweets % hitsPerPage > 0) maxPages++; } boolean breakPaging = false; for (int page = 0; page < maxPages; page++) { Query query = new Query(term); // RECENT or POPULAR query.setResultType(Query.MIXED); // avoid that more recent results disturb our paging! if (page > 0) query.setMaxId(maxId); query.setPage(page + 1); query.setRpp(hitsPerPage); QueryResult res = twitter.search(query); // is res.getTweets() sorted? for (Object o : res.getTweets()) { Tweet twe = (Tweet) o; // determine maxId in the first page if (page == 0 && maxId < twe.getId()) maxId = twe.getId(); if (maxMillis < twe.getCreatedAt().getTime()) maxMillis = twe.getCreatedAt().getTime(); if (twe.getCreatedAt().getTime() + 1000 < lastMaxCreateTime) breakPaging = true; else { String userName = twe.getFromUser().toLowerCase(); JUser user = userMap.get(userName); if (user == null) { user = new JUser(userName).init(twe); userMap.put(userName, user); } result.add(new JTweet(twe, user)); } } // minMillis could force us to leave earlier than defined by maxPages // or if resulting tweets are less then request (but -10 because of twitter strangeness) if (breakPaging || res.getTweets().size() < hitsPerPage - 10) break; } return maxMillis; }
From source file:org.kuali.mobility.conference.controllers.ConferenceController.java
License:Open Source License
@RequestMapping(value = "twitter-search", method = RequestMethod.GET) public ResponseEntity<String> twitterSearch(@RequestParam(value = "term", required = true) String searchParam, @RequestParam(value = "since", required = false) String sinceParam, HttpServletRequest request) { Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query(searchParam.isEmpty() ? "#kualidays" : searchParam); QueryResult result = null;/*from w ww.j a v a2 s .c om*/ query.setSince(!sinceParam.isEmpty() ? sinceParam : "2014-01-01"); query.setCount(100); query.setResultType(Query.MIXED); String json = ""; List<String> tweetList = new ArrayList<String>(); try { result = twitter.search(query); } catch (TwitterException e) { System.err.println("Caught 'twitterSearch' IOException: " + e.getMessage()); } String tweetInfo = ""; for (Status status : result.getTweets()) { tweetInfo = "{"; tweetInfo += "\"id\" : \"" + status.getId() + "\", "; tweetInfo += "\"avatar\" : \"" + status.getUser().getProfileImageURL() + "\", "; tweetInfo += "\"tweetedOn\" : \"" + status.getCreatedAt() + "\", "; tweetInfo += "\"tweetedOnParsed\" : \"" + status.getCreatedAt().getTime() + "\", "; tweetInfo += "\"screenname\" : \"" + status.getUser().getScreenName() + "\", "; tweetInfo += "\"status\" : \"" + StringEscapeUtils.escapeHtml(status.getText().replaceAll("(\\r|\\n)", "")) + "\", "; tweetInfo += "\"truncated\" : \"" + (status.isTruncated() ? "true" : "false") + "\","; tweetInfo += "\"retweeted\" : \"" + (status.isRetweet() ? "true" : "false") + "\""; tweetInfo += "}"; tweetList.add(tweetInfo); } json = "[" + StringUtils.arrayToDelimitedString(tweetList.toArray(), ",") + "]"; return new ResponseEntity<String>(json, HttpStatus.OK); }