List of usage examples for twitter4j Status getCreatedAt
Date getCreatedAt();
From source file:org.mariotaku.twidere.model.ParcelableStatus.java
License:Open Source License
public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) { this.is_gap = is_gap; this.account_id = account_id; id = orig.getId();/*from w ww.j av a 2 s . co m*/ timestamp = getTime(orig.getCreatedAt()); final Status retweeted = orig.getRetweetedStatus(); final User retweet_user = retweeted != null ? orig.getUser() : null; is_retweet = orig.isRetweet(); retweet_id = retweeted != null ? retweeted.getId() : -1; retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1; retweeted_by_user_id = retweet_user != null ? retweet_user.getId() : -1; retweeted_by_user_name = retweet_user != null ? retweet_user.getName() : null; retweeted_by_user_screen_name = retweet_user != null ? retweet_user.getScreenName() : null; retweeted_by_user_profile_image = retweet_user != null ? retweet_user.getProfileImageUrlHttps() : null; final Status quoted = orig.getQuotedStatus(); final User quote_user = quoted != null ? orig.getUser() : null; is_quote = orig.isQuote(); quote_id = quoted != null ? quoted.getId() : -1; quote_text_html = TwitterContentUtils.formatStatusText(orig); quote_text_plain = orig.getText(); quote_text_unescaped = HtmlEscapeHelper.toPlainText(quote_text_html); quote_timestamp = orig.getCreatedAt().getTime(); quote_source = orig.getSource(); quoted_by_user_id = quote_user != null ? quote_user.getId() : -1; quoted_by_user_name = quote_user != null ? quote_user.getName() : null; quoted_by_user_screen_name = quote_user != null ? quote_user.getScreenName() : null; quoted_by_user_profile_image = quote_user != null ? quote_user.getProfileImageUrlHttps() : null; quoted_by_user_is_protected = quote_user != null && quote_user.isProtected(); quoted_by_user_is_verified = quote_user != null && quote_user.isVerified(); final Status status; if (quoted != null) { status = quoted; } else if (retweeted != null) { status = retweeted; } else { status = orig; } final User user = status.getUser(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = user.getProfileImageUrlHttps(); user_is_protected = user.isProtected(); user_is_verified = user.isVerified(); user_is_following = user.isFollowing(); text_html = TwitterContentUtils.formatStatusText(status); media = ParcelableMedia.fromStatus(status); quote_media = quoted != null ? ParcelableMedia.fromStatus(orig) : null; text_plain = status.getText(); retweet_count = status.getRetweetCount(); favorite_count = status.getFavoriteCount(); reply_count = status.getReplyCount(); descendent_reply_count = status.getDescendentReplyCount(); in_reply_to_name = TwitterContentUtils.getInReplyToName(retweeted != null ? retweeted : orig); in_reply_to_screen_name = (retweeted != null ? retweeted : orig).getInReplyToScreenName(); in_reply_to_status_id = (retweeted != null ? retweeted : orig).getInReplyToStatusId(); in_reply_to_user_id = (retweeted != null ? retweeted : orig).getInReplyToUserId(); source = status.getSource(); location = ParcelableLocation.fromGeoLocation(status.getGeoLocation()); is_favorite = status.isFavorited(); text_unescaped = HtmlEscapeHelper.toPlainText(text_html); my_retweet_id = retweeted_by_user_id == account_id ? id : status.getCurrentUserRetweet(); is_possibly_sensitive = status.isPossiblySensitive(); mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities()); card = ParcelableCardEntity.fromCardEntity(status.getCard(), account_id); place_full_name = getPlaceFullName(status.getPlace()); card_name = card != null ? card.name : null; }
From source file:org.mariotaku.twidere.util.ContentValuesCreator.java
License:Open Source License
@NonNull public static ContentValues createStatus(final Status orig, final long accountId) { if (orig == null) throw new NullPointerException(); 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 a v a 2 s .co 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()); final ParcelableMedia[] quoteMedia = ParcelableMedia.fromStatus(orig); if (quoteMedia != null && quoteMedia.length > 0) { try { values.put(Statuses.QUOTE_MEDIA_JSON, LoganSquare.serialize(Arrays.asList(quoteMedia), ParcelableMedia.class)); } catch (IOException ignored) { } } 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); status = quotedStatus; } else { values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); status = orig; } if (orig.isRetweet()) { 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()); } else { values.put(Statuses.IN_REPLY_TO_STATUS_ID, orig.getInReplyToStatusId()); values.put(Statuses.IN_REPLY_TO_USER_ID, orig.getInReplyToUserId()); values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(orig)); values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, orig.getInReplyToScreenName()); } 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.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.fromStatus(status); if (media != null && media.length > 0) { try { values.put(Statuses.MEDIA_JSON, LoganSquare.serialize(Arrays.asList(media), ParcelableMedia.class)); } catch (IOException ignored) { } } final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status); if (mentions != null && mentions.length > 0) { try { values.put(Statuses.MENTIONS_JSON, LoganSquare.serialize(Arrays.asList(mentions), ParcelableUserMention.class)); } catch (IOException ignored) { } } final ParcelableCardEntity card = ParcelableCardEntity.fromCardEntity(status.getCard(), accountId); if (card != null) { try { values.put(Statuses.CARD, LoganSquare.serialize(card)); values.put(Statuses.CARD_NAME, card.name); } catch (IOException ignored) { } } return values; }
From source file:org.n52.twitter.model.TwitterMessage.java
License:Open Source License
public static TwitterMessage create(Status tweet) { if (isGeolocated(tweet)) { TwitterMessage result = new TwitterMessage(); result.id = Long.toString(tweet.getId()); result.procedure = new Procedure(tweet.getUser().getScreenName(), String.format(USER_URL, tweet.getUser().getScreenName())); result.location = new TwitterLocation(tweet.getGeoLocation(), tweet.getPlace()); result.createdTime = new DateTime(tweet.getCreatedAt(), DateTimeZone.UTC); result.link = String.format(TWEET_URL, tweet.getUser().getScreenName(), Long.toString(tweet.getId())); result.message = tweet.getText(); return result; }//from w ww .j a va2 s. c o m return null; }
From source file:org.nsoft.openbus.model.Mensagem.java
License:Open Source License
public static Mensagem creteFromTwitterStatus(Status s) { try {//from w w w . j a v a2 s . c om Mensagem mensagem = new Mensagem(); String text = s.getText(); for (HashtagEntity h : s.getHashtagEntities()) { String subText = "<a href=\"twitter_search://do_search?search=" + h.getText() + "\">#" + h.getText() + "</a>"; text = text.replace("#" + h.getText(), subText); } for (UserMentionEntity u : s.getUserMentionEntities()) { String subText = "<a href=\"twitter_search_user://find_user?username=" + u.getScreenName() + "\">@" + u.getScreenName() + "</a>"; text = text.replace("@" + u.getScreenName(), subText); } mensagem.setAction(OpenTwitterStatusAction.getInstance()); mensagem.addtions = createAddtions(s); mensagem.addtions.put("htmlText", text); mensagem.idMensagem = Long.toString(s.getId()); mensagem.nome_usuario = s.getUser().getName(); mensagem.mensagem = s.getText(); mensagem.imagePath = new URL(s.getUser().getOriginalProfileImageURL()); mensagem.data = s.getCreatedAt(); mensagem.idUser = s.getUser().getId(); mensagem.tipo = TIPO_STATUS; return mensagem; } catch (JSONException e) { return null; } catch (MalformedURLException e) { return null; } }
From source file:org.onebusaway.admin.service.impl.TwitterServiceImpl.java
License:Apache License
public String updateStatus(String statusMessage) throws IOException { if (statusMessage == null) { _log.info("nothing to tweet! Exiting"); return null; }//from w ww .ja v a 2 s. c om Map<String, String> params = new HashMap<>(); _log.info("tweeting: " + statusMessage); params.put("status", statusMessage); if (_twitter == null) { throw new IOException("Invalid Configuration: Missing consumer / access keys in spring configuration"); } String response = null; try { Status status = _twitter.updateStatus(statusMessage); if (status != null) { response = "Successfully tweeted \"" + status.getText() + "\" at " + status.getCreatedAt(); } } catch (TwitterException te) { _log.error(te.getExceptionCode() + ":" + ":" + te.getStatusCode() + te.getErrorMessage()); throw new IOException(te); } return response; }
From source file:org.onepercent.utils.twitterstream.agent.src.main.java.com.cloudera.flume.source.TwitterSource.java
License:Apache License
/** * Start processing events. This uses the Twitter Streaming API to sample * Twitter, and process tweets.//from w w w . j av a 2 s.co m */ @Override public void start() { // The channel is the piece of Flume that sits between the Source and Sink, // and is used to process events. final ChannelProcessor channel = getChannelProcessor(); final Map<String, String> headers = new HashMap<String, String>(); // The StatusListener is a twitter4j API, which can be added to a Twitter // stream, and will execute methods every time a message comes in through // the stream. StatusListener listener = new StatusListener() { // The onStatus method is executed every time a new tweet comes in. public void onStatus(Status status) { // The EventBuilder is used to build an event using the headers and // the raw JSON of a tweet logger.debug(status.getUser().getScreenName() + ": " + status.getText()); headers.put("timestamp", String.valueOf(status.getCreatedAt().getTime())); Event event = EventBuilder.withBody(DataObjectFactory.getRawJSON(status).getBytes(), headers); channel.processEvent(event); } // This listener will ignore everything except for new tweets public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } public void onScrubGeo(long userId, long upToStatusId) { } public void onException(Exception ex) { } public void onStallWarning(StallWarning warning) { } }; logger.debug("Setting up Twitter sample stream using consumer key {} and" + " access token {}", new String[] { consumerKey, accessToken }); // Set up the stream's listener (defined above), twitterStream.addListener(listener); // Set up a filter to pull out industry-relevant tweets if (keywords.length == 0) { logger.debug("Starting up Twitter sampling..."); twitterStream.sample(); } else if (keywords.length > 0) { if (languages.length == 0) { logger.debug("Starting up Twitter Keyword filtering..."); FilterQuery query = new FilterQuery().track(keywords); twitterStream.filter(query); } else { logger.debug("Starting up Twitter Keyword and Language filtering..."); FilterQuery query = new FilterQuery(); query.track(keywords); query.language(languages); twitterStream.filter(query); } } super.start(); }
From source file:org.opensocial.TwitterProxy.java
License:Apache License
/** * Called on HTTP GET/*w w w .j av a2s.c om*/ * Returns last 20 tweets from the user using "screen_name". * If screenName is null or an empty string, we return the last 20 tweets from the public * timeline * @param screenName * @return JSON Response a ActivityStream Activity collection for the set tweets */ @GET @Produces(MediaType.APPLICATION_JSON) public Object getTweets(@QueryParam("screen_name") String screenName) { JSONArray resultArray = new JSONArray(); ResponseList<Status> list = null; try { if (screenName == null || screenName.equals("")) { list = twitter.getHomeTimeline(); } else { list = twitter.getUserTimeline(screenName); } System.out.println("Rate limit: " + list.getRateLimitStatus().getRemainingHits()); Iterator<Status> iter = list.iterator(); while (iter.hasNext()) { Status status = iter.next(); ActivityBuilder activityBuilder = Activity.makeActivity().id(Long.toString(status.getId())) .verb(Verb.POST).published(new DateTime(status.getCreatedAt().getTime())) .source(ASObject.makeObject(ASObject.SOURCE).displayName(status.getSource())) .author(PersonObject.makePerson(status.getUser().getScreenName()) .id(Long.toString(status.getUser().getId())) .image(MediaLink .makeMediaLink(status.getUser().getProfileImageURL().toExternalForm())) .get()); boolean eeAdded = false; eeAdded = EmbeddedExperiences.addHashtagEE(uriInfo, status, activityBuilder); if (!eeAdded) { eeAdded = EmbeddedExperiences.addUrlMatchedEE(uriInfo, status, activityBuilder); } if (!eeAdded) { eeAdded = EmbeddedExperiences.addUrlStyleEE(status, activityBuilder); } activityBuilder.content(status.getText()); Activity activity = activityBuilder.get(); StringWriter swriter = new StringWriter(); activity.writeTo(swriter); JSONObject jobj = new JSONObject(swriter.toString()); resultArray.put(jobj); } return resultArray; } catch (Exception e) { e.printStackTrace(); return Response.serverError().entity(e).build(); } }
From source file:org.osframework.maven.plugins.twitter.TweetMojo.java
License:Apache License
private void logStatus(Status status) { StringBuilder logMsg = new StringBuilder(formatDate(status.getCreatedAt())).append(" ") .append(status.getText());//from ww w. j a va 2 s . c o m File logFile = new File(getWorkDirectory(), "tweet.log"); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(logFile, true)); writer.write(logMsg.toString()); } catch (IOException ioe) { getLog().warn("Could not write status to tweet.log"); } finally { IOUtil.close(writer); } }
From source file:org.rhq.plugins.twitter.TwitterEventPoller.java
License:Open Source License
/** * Add statuses to the list of events to return * @param statuses//from ww w . j a v a 2s . c o m */ public void addStatuses(List<Status> statuses) { synchronized (events) { for (Status status : statuses) { Event ev = new Event(getEventType(), // Event Type status.getUser().getName(), // SourceLocation status.getCreatedAt().getTime(), // Timestamp EventSeverity.INFO, // Severity -- just all the same for now status.getText()); events.add(ev); } } }
From source file:org.selman.tweetamo.PersistentStore.java
License:Apache License
private static Map<String, AttributeValue> newItem(Status status) { Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put(COL_ID, new AttributeValue().withN(Long.toString(status.getId()))); item.put(COL_CREATEDAT, new AttributeValue().withN(Long.toString(status.getCreatedAt().getTime()))); if (status.getGeoLocation() != null) { item.put(COL_LAT, new AttributeValue().withN(Double.toString(status.getGeoLocation().getLatitude()))); item.put(COL_LONG, new AttributeValue().withN(Double.toString(status.getGeoLocation().getLongitude()))); }/*from w ww . jav a2s .c o m*/ item.put(COL_SCREENNAME, new AttributeValue().withS(status.getUser().getScreenName())); item.put(COL_TEXT, new AttributeValue().withS(status.getText())); return item; }