List of usage examples for twitter4j Status getCreatedAt
Date getCreatedAt();
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createStatus(final Status orig, final long accountId) { if (orig == null || orig.getId() <= 0) return null; final ContentValues values = new ContentValues(); values.put(Statuses.ACCOUNT_ID, accountId); values.put(Statuses.STATUS_ID, orig.getId()); values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime()); final Status status; if (orig.isRetweet()) { final Status retweetedStatus = orig.getRetweetedStatus(); final User retweetUser = orig.getUser(); final long retweetedById = retweetUser.getId(); values.put(Statuses.RETWEET_ID, retweetedStatus.getId()); values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime()); values.put(Statuses.RETWEETED_BY_USER_ID, retweetedById); values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName()); values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName()); values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE, (retweetUser.getProfileImageUrlHttps())); values.put(Statuses.IS_RETWEET, true); if (retweetedById == accountId) { values.put(Statuses.MY_RETWEET_ID, orig.getId()); } else {/* w w w . j av a 2 s . c o m*/ values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); } status = retweetedStatus; } else if (orig.isQuote()) { final Status quotedStatus = orig.getQuotedStatus(); final User quoteUser = orig.getUser(); final long quotedById = quoteUser.getId(); values.put(Statuses.QUOTE_ID, quotedStatus.getId()); final String textHtml = TwitterContentUtils.formatStatusText(orig); values.put(Statuses.QUOTE_TEXT_HTML, textHtml); values.put(Statuses.QUOTE_TEXT_PLAIN, orig.getText()); values.put(Statuses.QUOTE_TEXT_UNESCAPED, toPlainText(textHtml)); values.put(Statuses.QUOTE_TIMESTAMP, orig.getCreatedAt().getTime()); values.put(Statuses.QUOTE_SOURCE, orig.getSource()); values.put(Statuses.QUOTED_BY_USER_ID, quotedById); values.put(Statuses.QUOTED_BY_USER_NAME, quoteUser.getName()); values.put(Statuses.QUOTED_BY_USER_SCREEN_NAME, quoteUser.getScreenName()); values.put(Statuses.QUOTED_BY_USER_PROFILE_IMAGE, quoteUser.getProfileImageUrlHttps()); values.put(Statuses.QUOTED_BY_USER_IS_VERIFIED, quoteUser.isVerified()); values.put(Statuses.QUOTED_BY_USER_IS_PROTECTED, quoteUser.isProtected()); values.put(Statuses.IS_QUOTE, true); if (quotedById == accountId) { values.put(Statuses.MY_QUOTE_ID, orig.getId()); // } else { // values.put(Statuses.MY_QUOTE_ID, orig.getCurrentUserRetweet()); } status = quotedStatus; } else { values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); status = orig; } final User user = status.getUser(); final long userId = user.getId(); final String profileImageUrl = (user.getProfileImageUrlHttps()); final String name = user.getName(), screenName = user.getScreenName(); values.put(Statuses.USER_ID, userId); values.put(Statuses.USER_NAME, name); values.put(Statuses.USER_SCREEN_NAME, screenName); values.put(Statuses.IS_PROTECTED, user.isProtected()); values.put(Statuses.IS_VERIFIED, user.isVerified()); values.put(Statuses.USER_PROFILE_IMAGE_URL, profileImageUrl); values.put(CachedUsers.IS_FOLLOWING, user.isFollowing()); final String textHtml = TwitterContentUtils.formatStatusText(status); values.put(Statuses.TEXT_HTML, textHtml); values.put(Statuses.TEXT_PLAIN, status.getText()); values.put(Statuses.TEXT_UNESCAPED, toPlainText(textHtml)); values.put(Statuses.RETWEET_COUNT, status.getRetweetCount()); values.put(Statuses.REPLY_COUNT, status.getReplyCount()); values.put(Statuses.FAVORITE_COUNT, status.getFavoriteCount()); values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount()); values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(status)); values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName()); values.put(Statuses.SOURCE, status.getSource()); values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive()); final GeoLocation location = status.getGeoLocation(); if (location != null) { values.put(Statuses.LOCATION, ParcelableLocation.toString(location.getLatitude(), location.getLongitude())); } final Place place = status.getPlace(); if (place != null) { values.put(Statuses.PLACE_FULL_NAME, place.getFullName()); } values.put(Statuses.IS_FAVORITE, status.isFavorited()); final ParcelableMedia[] media = ParcelableMedia.fromEntities(status); if (media != null) { values.put(Statuses.MEDIA_LIST, SimpleValueSerializer.toSerializedString(media)); } final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status); if (mentions != null) { values.put(Statuses.MENTIONS_LIST, SimpleValueSerializer.toSerializedString(mentions)); } final ParcelableCardEntity card = ParcelableCardEntity.fromCardEntity(status.getCard(), accountId); if (card != null) { values.put(Statuses.CARD_NAME, card.name); values.put(Statuses.CARD, JSONSerializer.toJSONObjectString(card)); } return values; }
From source file:org.glassfish.jersey.sample.sse.TwitterBean.java
License:Open Source License
/** * Since twitter uses the v1.1 API we use twitter4j to get * the search results using OAuth//from ww w .j a va2 s. co m * @return a JsonArray containing tweets * @throws TwitterException * @throws IOException */ public JsonArray getFeedData() throws TwitterException, IOException { Properties prop = new Properties(); // try { //load a properties file prop.load(this.getClass().getResourceAsStream("twitter4j.properties")); //get the property value and print it out String consumerKey = prop.getProperty("oauth.consumerKey"); String consumerSecret = prop.getProperty("oauth.consumerSecret"); String accessToken = prop.getProperty("oauth.accessToken"); String accessTokenSecret = prop.getProperty("oauth.accessTokenSecret"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); Query query = new Query("glassfish"); QueryResult result = twitter.search(query); JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder(); for (Status status : result.getTweets()) { jsonArrayBuilder.add(Json.createObjectBuilder().add("text", status.getText()).add("created_at", status.getCreatedAt().toString())); System.out.println( "@" + status.getUser().getScreenName() + ":" + status.getText() + status.getCreatedAt()); } return jsonArrayBuilder.build(); }
From source file:org.graylog2.inputs.twitter.TwitterCodec.java
License:Open Source License
private Message createMessageFromStatus(final Status status) { final Message message = new Message(status.getText(), "twitter.com", new DateTime(status.getCreatedAt())); message.addField("facility", "Tweets"); message.addField("level", 6); message.addField("tweet_id", status.getId()); message.addField("tweet_is_retweet", Boolean.toString(status.isRetweet())); message.addField("tweet_favorite_count", status.getFavoriteCount()); message.addField("tweet_retweet_count", status.getRetweetCount()); message.addField("tweet_language", status.getLang()); final GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { message.addField("tweet_geo_long", geoLocation.getLongitude()); message.addField("tweet_geo_lat", geoLocation.getLatitude()); }/*from w w w .j a v a 2 s . c o m*/ final User user = status.getUser(); if (user != null) { message.addField("tweet_url", "https://twitter.com/" + user.getScreenName() + "/status/" + status.getId()); message.addField("user_id", user.getId()); message.addField("user_name", user.getScreenName()); message.addField("user_description", user.getDescription()); message.addField("user_timezone", user.getTimeZone()); message.addField("user_utc_offset", user.getUtcOffset()); message.addField("user_location", user.getLocation()); message.addField("user_language", user.getLang()); message.addField("user_url", user.getURL()); message.addField("user_followers", user.getFollowersCount()); message.addField("user_tweets", user.getStatusesCount()); message.addField("user_favorites", user.getFavouritesCount()); } return message; }
From source file:org.hornetq.integration.twitter.impl.IncomingTweetsHandler.java
License:Apache License
private void putTweetIntoMessage(final Status status, final ServerMessage msg) { msg.getBodyBuffer().writeString(status.getText()); msg.putLongProperty(TwitterConstants.KEY_ID, status.getId()); msg.putStringProperty(TwitterConstants.KEY_SOURCE, status.getSource()); msg.putLongProperty(TwitterConstants.KEY_CREATED_AT, status.getCreatedAt().getTime()); msg.putBooleanProperty(TwitterConstants.KEY_IS_TRUNCATED, status.isTruncated()); msg.putLongProperty(TwitterConstants.KEY_IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); msg.putIntProperty(TwitterConstants.KEY_IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); msg.putBooleanProperty(TwitterConstants.KEY_IS_FAVORITED, status.isFavorited()); msg.putBooleanProperty(TwitterConstants.KEY_IS_RETWEET, status.isRetweet()); msg.putObjectProperty(TwitterConstants.KEY_CONTRIBUTORS, status.getContributors()); GeoLocation gl;/* www . java 2 s .c o m*/ if ((gl = status.getGeoLocation()) != null) { msg.putDoubleProperty(TwitterConstants.KEY_GEO_LOCATION_LATITUDE, gl.getLatitude()); msg.putDoubleProperty(TwitterConstants.KEY_GEO_LOCATION_LONGITUDE, gl.getLongitude()); } Place place; if ((place = status.getPlace()) != null) { msg.putStringProperty(TwitterConstants.KEY_PLACE_ID, place.getId()); } }
From source file:org.hubiquitus.hubotsdk.adapters.HTwitterAdapterInbox.java
License:Open Source License
/** * Function for transforming Tweet to HMessage * @param tweet from twitter4j//from w w w.jav a2s. com * @return HMessage of type hTweet */ private HMessage transformtweet(Status tweet) { HMessage message = new HMessage(); HTweet htweet = new HTweet(); if (("complete").equalsIgnoreCase(content)) { HTweetAuthor hauthortweet = new HTweetAuthor(); //Construct the location HLocation location = new HLocation(); if (tweet.getGeoLocation() != null) { HGeo geo = new HGeo(tweet.getGeoLocation().getLatitude(), tweet.getGeoLocation().getLongitude()); location.setPos(geo); message.setLocation(location); } //Construct the Place if (tweet.getPlace() != null) { if (tweet.getPlace().getStreetAddress() != null) { location.setAddr(tweet.getPlace().getStreetAddress()); } if (tweet.getPlace().getCountryCode() != null) { location.setCountryCode(tweet.getPlace().getCountryCode()); } if ((tweet.getPlace().getPlaceType() != null) && ("city".equalsIgnoreCase(tweet.getPlace().getPlaceType()))) { location.setCity(tweet.getPlace().getName()); } } //Construct the Authortweet JSONObject hauthortweet.setStatus(tweet.getUser().getStatusesCount()); hauthortweet.setFollowers(tweet.getUser().getFollowersCount()); hauthortweet.setFriends(tweet.getUser().getFriendsCount()); hauthortweet.setLocation(tweet.getUser().getLocation()); hauthortweet.setDescription(tweet.getUser().getDescription()); hauthortweet.setProfileImg(tweet.getUser().getProfileImageURL().toString()); hauthortweet.setUrl(tweet.getUser().getURL()); hauthortweet.setCreatedAt(tweet.getUser().getCreatedAt()); hauthortweet.setLang(tweet.getUser().getLang()); hauthortweet.setListeds(tweet.getUser().getListedCount()); hauthortweet.setGeo(tweet.getUser().isGeoEnabled()); hauthortweet.setVerified(tweet.getUser().isVerified()); hauthortweet.setName(tweet.getUser().getName()); //Construct the tweet JSONObject htweet.setId(tweet.getId()); try { htweet.setSource(tweet.getSource()); htweet.setAuthor(hauthortweet); } catch (MissingAttrException e) { log.error("message: ", e); } } // now manage the minimal list of attributes to get from twitter try { htweet.setText(tweet.getText()); } catch (MissingAttrException e) { log.error("message: ", e); } message.setPayload(htweet); message.setType("hTweet"); message.setAuthor(tweet.getUser().getScreenName() + "@twitter.com"); Date createdAt = tweet.getCreatedAt(); message.setPublished(createdAt); if (log.isDebugEnabled()) { log.debug("tweet(" + tweet + ") -> hMessage :" + message); } return message; }
From source file:org.ipccenter.newsagg.impl.twitterapi.TwitterPuller.java
public void parsePost(Status status) { News post = new News(); post.setSource("Twitter"); post.setStatus(0);//from w w w . j a v a2 s . co m post.setContent(status.getText()); StringBuilder url = new StringBuilder(); url.append("http://twitter.com/").append(status.getUser().getScreenName()).append("/statuses/") .append(String.valueOf(status.getId())); post.setUrl(url.toString()); post.setDate(status.getCreatedAt()); //post.setAuthor(status.getUser().getName()); postsList.add(post); }
From source file:org.kawalpemilukada.web.controller.SentimentAnalysis.java
private void cariText(JSONArray returnVals, Twitter twitter, String topic) throws ParseException { try {//from w w w . j a va2 s. com Query query = new Query(topic); query.setCount(100); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { JSONObject returnVal = new JSONObject(); returnVal.put("Text", tweet.getText()); //returnVal.put("HashtagEntities", tweet.getHashtagEntities().toString()); //returnVal.put("UserMentionEntities", tweet.getUserMentionEntities().toString()); returnVal.put("FavoriteCount", tweet.getFavoriteCount()); returnVal.put("RetweetCount", tweet.getRetweetCount()); returnVal.put("UserImg", tweet.getUser().getBiggerProfileImageURLHttps().toString()); returnVal.put("UserLink", "https://twitter.com/" + CommonServices.getVal(tweet.getUser().getScreenName())); returnVal.put("CreatedAt", JakartaTime(tweet.getCreatedAt()).toString()); returnVals.add(returnVal); } } while ((query = result.nextQuery()) != null); } catch (TwitterException te) { te.printStackTrace(); } }
From source file:org.kie.io.Entry.java
License:Apache License
public Entry(final Status status) { this.title = "@" + status.getUser().getScreenName() + ": " + status.getText(); this.link = "https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId(); this.createdAt = new DateTime(status.getCreatedAt()); this.type = EntryType.Twitter; }
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 ww w . ja v a 2s . 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); }
From source file:org.manalith.ircbot.plugin.tweetreader.TweetReader.java
License:Open Source License
private String getText(String twitterurl, UrlType type) { if (type == null) return null; // init twitter4j try {//from w w w. j av a2s . c o m initTwitter4j(); } catch (TwitterException e) { return e.getMessage(); } if (StringUtils.isEmpty(config.getString("com.twitter.accessKey")) || StringUtils.isEmpty(config.getString("com.twitter.accessSecret"))) { try { authorizeTwitter(); } catch (TwitterException e) { return "[twitter4j.TwitterException] " + e.getMessage(); } catch (ConfigurationException e) { return "[org.apache.common.configuration.ConfigutaionException] " + e.getMessage(); } } else { String accessToken = config.getString("com.twitter.accessKey"); String accessSecret = config.getString("com.twitter.accessSecret"); setAcecssToken(accessToken, accessSecret); } Status stat = null; try { stat = getStatus(twitterurl, type); } catch (TwitterException e) { return "[twitter4j.TwitterException] " + e.getMessage(); } if (stat == null) return null; String author = stat.getUser().getName(); String createdAt = DateFormatUtils.format(stat.getCreatedAt(), TARGET_DATE_PATTERN); String message = stat.getText(); return String.format("?: %s, ?: %s, : %s", author, createdAt, message); }