List of usage examples for twitter4j Status getUser
User getUser();
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static Map getFieldsMapFromStatus(String queryOwner, String queryName, String queryString, Status status) { if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); Map m = StatusArraysHelper.getUserMentionMap(status); Map newMap = new HashMap(); for (Object key : m.keySet()) { newMap.put(key.toString(), (Long) m.get(key)); }//from w ww . j a v a 2s. co m Double longitude = null; Double lattitude = null; if (status.getGeoLocation() != null) { longitude = status.getGeoLocation().getLongitude(); lattitude = status.getGeoLocation().getLatitude(); } String place = null; if (status.getPlace() != null) { place = status.getPlace().getFullName(); } boolean isRetweet = status.getRetweetedStatus() != null; Long retweetedId = null; String retweetedText = null; if (isRetweet) { retweetedId = status.getRetweetedStatus().getId(); retweetedText = status.getRetweetedStatus().getText(); } Map<String, Object> result = new HashMap<>(); result.put(QueryResultItemFieldNames.STATUS_ID, status.getId()); result.put(QueryResultItemFieldNames.CREATED_AT, status.getCreatedAt()); result.put(QueryResultItemFieldNames.CURRENT_USER_RETWEET_ID, status.getCurrentUserRetweetId()); result.put(QueryResultItemFieldNames.FAVOURITE_COUNT, status.getFavoriteCount()); result.put(QueryResultItemFieldNames.FAVOURITED, status.isFavorited()); result.put(QueryResultItemFieldNames.HASHTAGS, StatusArraysHelper.getHashTagsList(status)); result.put(QueryResultItemFieldNames.IN_REPLY_TO_SCREEN_NAME, (status.getInReplyToScreenName())); result.put(QueryResultItemFieldNames.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); result.put(QueryResultItemFieldNames.IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); result.put(QueryResultItemFieldNames.LATITUDE, lattitude); result.put(QueryResultItemFieldNames.LONGITUDE, longitude); result.put(QueryResultItemFieldNames.MENTIONS, newMap); result.put(QueryResultItemFieldNames.LANGUAGE, status.getLang()); result.put(QueryResultItemFieldNames.PLACE, place); result.put(QueryResultItemFieldNames.POSSIBLY_SENSITIVE, status.isPossiblySensitive()); result.put(QueryResultItemFieldNames.QUERY_NAME, queryName); result.put(QueryResultItemFieldNames.QUERY_OWNER, queryOwner); result.put(QueryResultItemFieldNames.QUERY, queryString); result.put(QueryResultItemFieldNames.RELEVANT_QUERY_TERMS, TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.put(QueryResultItemFieldNames.RETWEET, isRetweet); result.put(QueryResultItemFieldNames.RETWEET_COUNT, status.getRetweetCount()); result.put(QueryResultItemFieldNames.RETWEETED, status.isRetweeted()); result.put(QueryResultItemFieldNames.RETWEETED_BY_ME, status.isRetweetedByMe()); result.put(QueryResultItemFieldNames.RETWEET_STATUS_ID, retweetedId); result.put(QueryResultItemFieldNames.RETWEETED_TEXT, retweetedText); result.put(QueryResultItemFieldNames.SCOPES, StatusArraysHelper.getScopesList(status)); result.put(QueryResultItemFieldNames.SCREEN_NAME, status.getUser().getScreenName()); result.put(QueryResultItemFieldNames.SOURCE, (status.getSource())); result.put(QueryResultItemFieldNames.TEXT, (status.getText())); result.put(QueryResultItemFieldNames.TRUNCATED, status.isTruncated()); result.put(QueryResultItemFieldNames.URLS, StatusArraysHelper.getUrlsList(status)); result.put(QueryResultItemFieldNames.USER_ID, status.getUser().getId()); result.put(QueryResultItemFieldNames.USER_NAME, (status.getUser().getName())); result.put(QueryResultItemFieldNames.USER_DESCRIPTION, (status.getUser().getDescription())); result.put(QueryResultItemFieldNames.USER_LOCATION, (status.getUser().getLocation())); result.put(QueryResultItemFieldNames.USER_URL, (status.getUser().getURL())); result.put(QueryResultItemFieldNames.USER_IS_PROTECTED, status.getUser().isProtected()); result.put(QueryResultItemFieldNames.USER_FOLLOWERS_COUNT, status.getUser().getFollowersCount()); result.put(QueryResultItemFieldNames.USER_CREATED_AT, status.getUser().getCreatedAt()); result.put(QueryResultItemFieldNames.USER_FRIENDS_COUNT, status.getUser().getFriendsCount()); result.put(QueryResultItemFieldNames.USER_LISTED_COUNT, status.getUser().getListedCount()); result.put(QueryResultItemFieldNames.USER_STATUSES_COUNT, status.getUser().getStatusesCount()); result.put(QueryResultItemFieldNames.USER_FAVOURITES_COUNT, status.getUser().getFavouritesCount()); return result; }
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString, Status status) { TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro(); if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); result.setQueryName(queryName);//w w w. j a v a2s . c om result.setQueryOwner(queryOwner); result.setQuery(queryString); result.setStatusId(status.getId()); result.setText(status.getText()); result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.setLang(status.getLang()); result.setCreatedAt(status.getCreatedAt().getTime()); User user = status.getUser(); result.setUserId(user.getId()); result.setScreenName(user.getScreenName()); result.setUserLocation(user.getLocation()); result.setUserName(user.getName()); result.setUserDescription(user.getDescription()); result.setUserIsProtected(user.isProtected()); result.setUserFollowersCount(user.getFollowersCount()); result.setUserCreatedAt(user.getCreatedAt().getTime()); result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt())); result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt())); result.setUserFriendsCount(user.getFriendsCount()); result.setUserListedCount(user.getListedCount()); result.setUserStatusesCount(user.getStatusesCount()); result.setUserFavoritesCount(user.getFavouritesCount()); result.setCurrentUserRetweetId(status.getCurrentUserRetweetId()); result.setInReplyToScreenName(status.getInReplyToScreenName()); result.setInReplyToStatusId(status.getInReplyToStatusId()); result.setInReplyToUserId(status.getInReplyToUserId()); if (status.getGeoLocation() != null) { result.setLatitude(status.getGeoLocation().getLatitude()); result.setLongitude(status.getGeoLocation().getLongitude()); } result.setSource(status.getSource()); result.setTrucated(status.isTruncated()); result.setPossiblySensitive(status.isPossiblySensitive()); result.setRetweet(status.getRetweetedStatus() != null); if (result.getRetweet()) { result.setRetweetStatusId(status.getRetweetedStatus().getId()); result.setRetweetedText(status.getRetweetedStatus().getText()); } result.setRetweeted(status.isRetweeted()); result.setRetweetCount(status.getRetweetCount()); result.setRetweetedByMe(status.isRetweetedByMe()); result.setFavoriteCount(status.getFavoriteCount()); result.setFavourited(status.isFavorited()); if (status.getPlace() != null) { result.setPlace(status.getPlace().getFullName()); } Scopes scopesObj = status.getScopes(); if (scopesObj != null) { List scopes = Arrays.asList(scopesObj.getPlaceIds()); result.setScopes(scopes); } return result; }
From source file:com.redhat.ipaas.example.TweetToContactMapper.java
License:Apache License
@Override public void process(Exchange exchange) throws Exception { Message in = exchange.getIn();/*w ww.j av a 2 s .c o m*/ Status status = exchange.getIn().getBody(Status.class); User user = status.getUser(); String name = user.getName(); String screenName = user.getScreenName(); Contact contact = new Contact(); contact.setLastName(name); contact.setTwitterScreenName__c(screenName); in.setBody(contact); }
From source file:com.revolucion.secretwit.ui.timeline.TweetCellRenderer.java
License:Open Source License
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setComponentOrientation(list.getComponentOrientation()); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else {//from w w w . j a va 2 s . c om // Check for rollover Color backgroundColor = list.getBackground(); ListUI ui = list.getUI(); if (ui instanceof TimelineListUI) { int rolledOverIndex = ((TimelineListUI) ui).getRolledOverIndex(); if (rolledOverIndex != -1 && rolledOverIndex == index) { backgroundColor = Colors.TIMELINE_ROLLOVER; } } setBackground(backgroundColor); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); Status status = (Status) value; if (status != null) { BufferedImage image = loadImage(status); labelIcon.setIcon(new ImageIcon(image)); labelDate.setText(new PrettyTime().format(status.getCreatedAt()) + " via " + parseSource(status)); labelUsername.setText(status.getUser().getScreenName()); labelRealname.setText(status.getUser().getName()); String statusText = status.getText(); areaMessage.setText(statusText); if (StegoUtils.doesProfileImageHaveWatermark(image)) { String decodedStatus = StegoUtils.decodeTweet(statusText); if (decodedStatus != null && !decodedStatus.isEmpty()) { labelSecret.setText(decodedStatus); labelSecret.setVisible(true); } else labelSecret.setVisible(false); } else labelSecret.setVisible(false); } return this; }
From source file:com.revolucion.secretwit.ui.timeline.TweetCellRenderer.java
License:Open Source License
private BufferedImage loadImage(Status status) { if (status == null || status.getUser() == null || status.getUser().getProfileImageURL() == null) return null; URL url = status.getUser().getProfileImageURL(); return cache.requestThumbnail(url); }
From source file:com.rhymestore.twitter.stream.GetMentionsListener.java
License:Open Source License
@Override public void onStatus(final Status status) { UserMentionEntity[] mentions = status.getUserMentionEntities(); if (mentions != null) { for (UserMentionEntity mention : mentions) { try { // Check if there is any mention to us if (isCurrentUser(twitter, mention.getScreenName())) { // Only reply if it is a valid mention if (isValidMention(status) && !isCurrentUser(twitter, status.getUser().getScreenName())) { LOGGER.debug("Processing tweet {} from {}", status.getId(), status.getUser().getScreenName()); ReplyCommand reply = new ReplyCommand(twitter, wordParser, rhymeStore, status); reply.execute(); } else { LOGGER.debug("Ignoring mention: {}", status.getText()); }// ww w. j av a 2 s . c om // Do not process the same tweet more than once break; } } catch (TwitterException ex) { LOGGER.error("Could not process status: {}", status.getText()); } } } }
From source file:com.richardstansbury.tweetfollow.TwitterHelper.java
License:Open Source License
/** * Process's received Twitter status updates based upon the filter query. * * Implemented as part of the Status Listener Class. * @param status - a status update received by the listener. *//*from w w w. jav a 2 s. c om*/ @Override public void onStatus(Status status) { String tweetStr = status.getUser().getScreenName() + ": " + status.getText() + "(" + status.getCreatedAt() + ")"; _tweets.add(0, tweetStr); _parent.runOnUiThread(new Runnable() { @Override public void run() { _adapter.notifyDataSetChanged(); } }); }
From source file:com.rowland.hashtrace.utility.Utility.java
License:Apache License
public static Tweet createTweet(Status status) { User user = status.getUser(); long tweet_id = status.getId(); String tweet_text = status.getText(); Date tweet_text_date = status.getCreatedAt(); int tweet_retweet_count = status.getRetweetCount(); int tweet_favourite_count = status.getFavoriteCount(); int tweet_mentions_count = status.getUserMentionEntities().length; String user_name = user.getScreenName(); String user_image_url = user.getBiggerProfileImageURL(); String user_cover_url = user.getProfileBackgroundImageURL(); String user_location = user.getLocation(); String user_description = user.getDescription(); Tweet tweet = new Tweet(tweet_id, tweet_text, tweet_text_date, tweet_retweet_count, tweet_favourite_count, tweet_mentions_count, user_name, user_image_url, user_location, user_description, user_cover_url); return tweet; }
From source file:com.spec.CityTwitterSource.java
License:Apache License
/** * Start processing events. This uses the Twitter Streaming API to sample * Twitter, and process tweets./*from w w w .j a va 2 s .c o 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 flag = false; for (int i = 0; i < cities.length; i++) { if (status.getUser().getLocation().toLowerCase().contains(cities[i].toLowerCase())) flag = true; } if (flag) { logger.debug(status.getUser().getLocation() + " : " + flag); headers.put("timestamp", String.valueOf(status.getCreatedAt().getTime())); Event event = EventBuilder.withBody(DataObjectFactory.getRawJSON(status.getUser()).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 sw) { } }; //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), and set any necessary // security information. twitterStream.addListener(listener); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); twitterStream.setOAuthAccessToken(token); // Set up a filter to pull out industry-relevant tweets if (keywords.length == 0) { logger.debug("Starting up Twitter sampling..."); twitterStream.sample(); } else { logger.debug("Starting up Twitter filtering..."); FilterQuery query = new FilterQuery().track(keywords); twitterStream.filter(query); } super.start(); }
From source file:com.sstrato.flume.source.TwitterSource.java
License:Apache License
/** * Start processing events. This uses the Twitter Streaming API to sample * Twitter, and process tweets./*w w w. j av a 2 s .c o m*/ */ @Override public void start() { // ? ? final ChannelProcessor channel = getChannelProcessor(); final Map<String, String> headers = new HashMap<String, String>(); // ? twitter4j? StatusListener ? ?. StatusListener listener = new StatusListener() { // The onStatus method is executed every time a new tweet comes in. public void onStatus(Status status) { // header raw json ? ? . 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) { } @Override public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; logger.debug("Setting up Twitter sample stream using consumer key {} and" + " access token {}", new String[] { this.consumerKey, this.accessToken }); // Set up the stream's listener (defined above), and set any necessary // security information. twitterStream.addListener(listener); twitterStream.setOAuthConsumer(this.consumerKey, this.consumerSecret); AccessToken token = new AccessToken(this.accessToken, this.accessTokenSecret); twitterStream.setOAuthAccessToken(token); // Set up a filter to pull out industry-relevant tweets if (keywords.length == 0) { logger.debug("Starting up Twitter sampling..."); twitterStream.sample(); } else { logger.debug("Starting up Twitter filtering..."); // ? . FilterQuery query = new FilterQuery().track(keywords); twitterStream.filter(query); } super.start(); }