List of usage examples for twitter4j Status getText
String getText();
From source file:org.tomitribe.chatterbox.twitter.adapter.TwitterResourceAdapter.java
License:Apache License
private static String getNormalizedText(Status status) { String text = status.getText(); while (text.startsWith("@")) { text = text.replaceFirst("@?(\\w){1,15}(\\s+)", ""); }/*from w ww . jav a 2 s . c o m*/ return text; }
From source file:org.tweetalib.android.model.TwitterStatus.java
License:Apache License
public TwitterStatus(Status status) { User statusUser = status.getUser();//from w w w . j av a 2 s .c o m mCreatedAt = status.getCreatedAt(); mId = status.getId(); if (status.getInReplyToStatusId() != -1) { mInReplyToStatusId = status.getInReplyToStatusId(); } if (status.getInReplyToUserId() != -1) { mInReplyToUserId = status.getInReplyToUserId(); } mInReplyToUserScreenName = status.getInReplyToScreenName(); mIsFavorited = status.isFavorited(); mIsRetweet = status.isRetweet(); mIsRetweetedByMe = status.isRetweetedByMe(); mSource = TwitterUtil.stripMarkup(status.getSource()); if (statusUser != null) { mUserId = statusUser.getId(); mUserName = statusUser.getName(); mUserScreenName = statusUser.getScreenName(); } mMediaEntity = TwitterMediaEntity.createMediaEntity(status); boolean useDefaultAuthor = true; if (mIsRetweet) { if (status.getRetweetedStatus() != null && status.getRetweetedStatus().getUser() != null) { SetProfileImagesFromUser(new TwitterUser(status.getRetweetedStatus().getUser())); } mOriginalRetweetId = status.getRetweetedStatus().getId(); // You'd think this check wasn't necessary, but apparently not... UserMentionEntity[] userMentions = status.getUserMentionEntities(); if (userMentions != null && userMentions.length > 0) { useDefaultAuthor = false; UserMentionEntity authorMentionEntity = status.getUserMentionEntities()[0]; mAuthorId = authorMentionEntity.getId(); mAuthorName = authorMentionEntity.getName(); mAuthorScreenName = authorMentionEntity.getScreenName(); Status retweetedStatus = status.getRetweetedStatus(); mStatus = retweetedStatus.getText(); setStatusMarkup(retweetedStatus); mRetweetCount = retweetedStatus.getRetweetCount(); mUserMentions = TwitterUtil.getUserMentions(retweetedStatus.getUserMentionEntities()); mIsRetweetedByMe = retweetedStatus.isRetweetedByMe(); } } else { if (statusUser != null) { SetProfileImagesFromUser(new TwitterUser(statusUser)); } } if (useDefaultAuthor) { if (statusUser != null) { mAuthorId = statusUser.getId(); } mStatus = status.getText(); setStatusMarkup(status); mRetweetCount = status.getRetweetCount(); mUserMentions = TwitterUtil.getUserMentions(status.getUserMentionEntities()); } /* * if (status.getId() == 171546910249852928L) { mStatus = * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?" * ; mStatusMarkup = * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?" * ; mAuthorScreenName = "emmarclarke"; mStatusMarkup = mStatus; } else * if (status.getId() == 171444098698457089L) { mStatus = * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?" * ; mStatusMarkup = * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?" * ; mStatusMarkup = mStatus; } */ }
From source file:org.tweetalib.android.TwitterUtil.java
License:Apache License
public static String getStatusMarkup(Status status) { return getStatusMarkup(status.getText(), status.getMediaEntities(), status.getURLEntities(), showFullUrl); }
From source file:org.twitter.oauth.java
public static void main(String args[]) throws Exception { // The factory instance is re-useable and thread safe. Twitter twitter = TwitterFactory.getSingleton(); twitter.setOAuthConsumer("SjLUa1Pwrs81nIAGiR4f1l4I7", "ISAXBmzqzYLKWQXAaOe09j34APvVOyxahHghLBSvvR0Psnhozl"); RequestToken requestToken = twitter.getOAuthRequestToken(); AccessToken accessToken = null;/*from w w w . j a v a 2 s . c om*/ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } //persist to the accessToken for future reference. storeAccessToken((int) twitter.verifyCredentials().getId(), accessToken); Status status = twitter.updateStatus(args[0]); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); }
From source file:org.umd.assignment.spout.TwitterSampleSpout.java
License:Apache License
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<String>(1000); _collector = collector;// w ww. j a va2s. co m StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { queue.offer(status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { } @Override public void onTrackLimitationNotice(int i) { } @Override public void onScrubGeo(long l, long l1) { } @Override public void onException(Exception ex) { } @Override public void onStallWarning(StallWarning arg0) { } }; TwitterStreamFactory fact = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()); _twitterStream = fact.getInstance(); _twitterStream.addListener(listener); _twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); _twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { _twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } }
From source file:org.unimonk.flume.source.twitter.TwitterSource.java
License:Apache License
@Override public void start() { final ChannelProcessor channel = getChannelProcessor(); StatusListener listener = new StatusListener() { @Override/*from ww w . j a v a 2 s . c o m*/ public void onStatus(Status status) { Tweet tweet = new Tweet(); tweet.setId(status.getId()); tweet.setUserId(status.getUser().getId()); tweet.setLatitude(status.getGeoLocation().getLatitude()); tweet.setLongitude(status.getGeoLocation().getLongitude()); tweet.setText(status.getText()); tweet.setCreatedAt(new Timestamp(status.getCreatedAt().getTime())); Event event = EventBuilder.withBody(tweet.toString(), Charsets.UTF_8); sourceCounter.incrementAppendReceivedCount(); try { channel.processEvent(event); sourceCounter.incrementEventAcceptedCount(); } catch (ChannelException ex) { logger.error("In Twitter source {} : Unable to process event due to exception {}.", getName(), ex); } } // This listener will ignore everything except for new tweets @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } @Override public void onScrubGeo(long userId, long upToStatusId) { } @Override public void onException(Exception ex) { } @Override public void onStallWarning(StallWarning arg0) { } }; logger.debug("Setting up Twitter sample stream using consumer key {} and" + " access token {}", new String[] { consumerKey, accessToken }); twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addListener(listener); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); twitterStream.setOAuthAccessToken(token); 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); } this.sourceCounter.start(); super.start(); }
From source file:org.vsepml.storm.sensapp.SensAppBolt.java
License:Apache License
@Override public void execute(Tuple tuple) { Status tweet = (Status) tuple.getValueByField("tweet"); LinkedList<ValueJsonModel> l = new LinkedList<ValueJsonModel>(); l.add(new StringValueJsonModel(tweet.getText(), tweet.getCreatedAt().getTime())); StringMeasureJsonModel m = new StringMeasureJsonModel(name, tweet.getCreatedAt().getTime(), "m", l); try {/*from w w w . j a va 2 s .co m*/ String jsonString = mapper.writeValueAsString(m); RestRequest.putData(new URI(endPoint), jsonString); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:org.wandora.application.tools.extractors.twitter.AbstractTwitterExtractor.java
License:Open Source License
public Topic reifyTweet(Status t, TopicMap tm) { Topic tweetTopic = null;//from w w w .j a va2 s. c om try { long tId = t.getId(); String msg = t.getText(); User user = t.getUser(); if (user == null) { tweetTopic = reifyTweet(tId, null, msg, tm); } else { String userScreenName = user.getScreenName(); tweetTopic = reifyTweet(tId, userScreenName, msg, tm); Topic userTopic = reifyTwitterUser(user, tm); if (tweetTopic != null && userTopic != null) { Association a = tm.createAssociation(getTwitterFromUserType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(userTopic, getTwitterUserType(tm)); } } /* String toUser = t.getToUser(); if(toUser != null) { long toUid = t.getToUserId(); Topic toUserTopic = reifyTwitterUser(toUser, toUid, tm); if(tweetTopic != null && toUserTopic != null) { Association a = tm.createAssociation(getTwitterToUserType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(toUserTopic, getTwitterUserType(tm)); } } */ Date d = t.getCreatedAt(); if (tweetTopic != null && d != null) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = df.format(d); tweetTopic.setData(getTweetDateType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG), dateStr); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); dateStr = sdf.format(d); Topic dateTopic = ExtractHelper.getOrCreateTopic(DATE_SI_BODY + dateStr, dateStr, getTweetDateType(tm), tm); if (dateTopic != null) { Association a = tm.createAssociation(getTweetDateType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(dateTopic, getTweetDateType(tm)); } } /* String l = t.getIsoLanguageCode(); if(l != null) { Topic tweetLangTopic = TMBox.getLangTopic(tweetTopic, l); if(tweetLangTopic != null) { Association a = tm.createAssociation(getTweetLangType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(tweetLangTopic, getTweetLangType(tm)); } } */ GeoLocation geo = t.getGeoLocation(); if (geo != null) { double lat = geo.getLatitude(); double lon = geo.getLongitude(); String geoLocStr = lat + "," + lon; tweetTopic.setData(getTweetGeoLocationType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG), geoLocStr); } HashtagEntity[] entities = t.getHashtagEntities(); if (entities != null && entities.length > 0) { for (int i = 0; i < entities.length; i++) { Topic entityTopic = reifyHashtagEntity(entities[i], tm); if (entityTopic != null) { Association a = tm.createAssociation(getHashtagType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(entityTopic, getHashtagType(tm)); } } } MediaEntity[] mediaEntities = t.getMediaEntities(); if (mediaEntities != null && mediaEntities.length > 0) { for (int i = 0; i < mediaEntities.length; i++) { Topic entityTopic = reifyMediaEntity(mediaEntities[i], tm); if (entityTopic != null) { Association a = tm.createAssociation(getMediaEntityType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(entityTopic, getMediaEntityType(tm)); } } } URLEntity[] urlEntities = t.getURLEntities(); if (urlEntities != null && urlEntities.length > 0) { for (int i = 0; i < urlEntities.length; i++) { Topic entityTopic = reifyUrlEntity(urlEntities[i], tm); if (entityTopic != null) { Association a = tm.createAssociation(getURLEntityType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(entityTopic, getURLEntityType(tm)); } } } } catch (Exception e) { log(e); } return tweetTopic; }
From source file:org.wso2.carbon.connector.twitter.TwitterRetweetStatus.java
License:Open Source License
public void connect(MessageContext messageContext) throws ConnectException { try {/*from w w w . j av a 2 s. c om*/ String id = TwitterUtils.lookupTemplateParamater(messageContext, ID); Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); Status status = twitter.retweetStatus(Long.parseLong(id)); TwitterUtils.storeResponseStatus(messageContext, status); if (log.isDebugEnabled()) { log.info("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { log.error("Failed to retweet status: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterUtils.java
License:Open Source License
public static void storeResponseStatus(MessageContext ctxt, Status status) { ctxt.setProperty(TwitterConnectConstants.TWITTER_STATUS_USER_SCREEN_NAME, status.getUser().getScreenName()); ctxt.setProperty(TwitterConnectConstants.TWITTER_STATUS_STATUS_TEXT, status.getText()); ctxt.setProperty(TwitterConnectConstants.TWITTER_API_RESPONSE, status); }