List of usage examples for twitter4j Status getText
String getText();
From source file:com.marklogic.tweetdeck.SaveRawJSON.java
License:Apache License
/** * Usage: java twitter4j.examples.json.SaveRawJSON * * @param args// ww w .j av a 2 s . co m * String[] */ public static void main(String[] args) { Twitter twitter = new TwitterFactory().getInstance(); System.out.println("Saving public timeline."); try { new File("statuses").mkdir(); List<Status> statuses = twitter.getHomeTimeline(); for (Status status : statuses) { String rawJSON = TwitterObjectFactory.getRawJSON(status); String fileName = "statuses/" + status.getId() + ".json"; storeJSON(rawJSON, fileName); System.out.println(fileName + " - " + status.getText()); } System.out.print("\ndone."); System.exit(0); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to store tweets: " + ioe.getMessage()); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:com.marpies.ane.twitter.functions.DeleteStatusFunction.java
License:Apache License
@Override public void destroyedStatus(Status destroyedStatus) { AIR.log("Success destroying status '" + destroyedStatus.getText() + "'"); StatusUtils.dispatchStatus(destroyedStatus, mCallbackID); }
From source file:com.marpies.ane.twitter.functions.LikeStatusFunction.java
License:Apache License
@Override public void createdFavorite(Status status) { AIR.log("Success liking status '" + status.getText() + "'"); StatusUtils.dispatchStatus(status, mCallbackID); }
From source file:com.marpies.ane.twitter.functions.RetweetStatusFunction.java
License:Apache License
@Override public void retweetedStatus(Status retweetedStatus) { AIR.log("Retweet of '" + retweetedStatus.getText() + "' success"); StatusUtils.dispatchStatus(retweetedStatus, mCallbackID); }
From source file:com.marpies.ane.twitter.functions.UndoLikeStatusFunction.java
License:Apache License
@Override public void destroyedFavorite(Status status) { AIR.log("Success removing liked status '" + status.getText() + "'"); StatusUtils.dispatchStatus(status, mCallbackID); }
From source file:com.marpies.ane.twitter.functions.UpdateStatusFunction.java
License:Apache License
@Override public void updatedStatus(Status status) { AIR.log("Updated status w/ message " + status.getText()); try {//from ww w . ja va 2 s. c om JSONObject statusJSON = StatusUtils.getJSON(status); statusJSON.put("listenerID", mCallbackID); statusJSON.put("success", true); AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_SUCCESS, statusJSON.toString()); } catch (JSONException e) { e.printStackTrace(); AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_SUCCESS, StringUtils.getEventErrorJSON(mCallbackID, "Status update succeeded but could not parse returned status.")); } }
From source file:com.marpies.ane.twitter.utils.StatusUtils.java
License:Apache License
public static JSONObject getJSON(Status status) throws JSONException { JSONObject statusJSON = new JSONObject(); statusJSON.put("id", status.getId()); statusJSON.put("idStr", String.valueOf(status.getId())); statusJSON.put("text", status.getText()); statusJSON.put("replyToUserID", status.getInReplyToUserId()); statusJSON.put("replyToStatusID", status.getInReplyToStatusId()); statusJSON.put("likesCount", status.getFavoriteCount()); statusJSON.put("retweetCount", status.getRetweetCount()); statusJSON.put("isRetweet", status.isRetweet()); statusJSON.put("isSensitive", status.isPossiblySensitive()); statusJSON.put("createdAt", status.getCreatedAt()); Status retweetedStatus = status.getRetweetedStatus(); if (retweetedStatus != null) { statusJSON.put("retweetedStatus", getJSON(retweetedStatus)); }/* www . j a va2 s . co m*/ User user = status.getUser(); if (user != null) { statusJSON.put("user", UserUtils.getJSON(user)); } return statusJSON; }
From source file:com.michaelfitzmaurice.clocktwerk.TweetResponder.java
License:Apache License
public Collection<Status> getNewMentions() throws TweetException { long sinceId = lastSeenMention(); try {// w ww . ja v a2 s . co m LOG.info("Checking for new Twitter mentions of {} since Tweet {}", myScreenName, sinceId); Paging paging = new Paging(sinceId); ResponseList<Status> mentions = twitterClient.getMentionsTimeline(paging); int numberOfMentions = mentions.size(); LOG.info("Found {} new mentions", numberOfMentions); for (Status status : mentions) { User user = status.getUser(); String mentionSummary = format("Date:%s, ID:%s, From:%s (%s), Text:'%s'", status.getCreatedAt(), status.getId(), user.getScreenName(), user.getName(), status.getText()); LOG.debug("New mention: [{}]", mentionSummary); } return mentions; } catch (TwitterException e) { throw new TweetException("Error getting Twitter mentions", e); } // TODO handle paging }
From source file:com.mothsoft.alexis.engine.retrieval.TwitterRetrievalTaskImpl.java
License:Apache License
private void handleSourceImpl(final TwitterSource twitterSource) { final SocialConnection socialConnection = twitterSource.getSocialConnection(); final AccessToken accessToken = new AccessToken(socialConnection.getOauthToken(), socialConnection.getOauthTokenSecret()); final List<Status> statuses = this.twitterService.getHomeTimeline(accessToken, twitterSource.getLastTweetId(), (short) 800); if (statuses != null && statuses.size() > 0) { logger.info("Twitter retrieval found " + statuses.size() + " Tweets for user: " + socialConnection.getRemoteUsername()); // the newest tweet in the timeline will be our starting point for // the next fetch twitterSource.setLastTweetId(statuses.get(0).getId()); // import these in reverse order to ensure newest ones have the // highest document IDs Collections.reverse(statuses); final Long userId = twitterSource.getUserId(); final User user = this.userDao.get(userId); for (final Status status : statuses) { final Long tweetId = status.getId(); Tweet tweet = this.tweetDao.getTweetByRemoteTweetId(tweetId); final boolean isAdd = (tweet == null); if (isAdd) { // TODO - is this right? // Twitter allows 2 different styles of retweets. The // ones that are actually retweets show as tweeted by the // original user. Others may show // "RT @original thing original said" tweeted // by the new person final boolean retweet = status.isRetweet(); final twitter4j.User tweeter; final String text; twitter4j.User retweeter = null; final List<TweetLink> links; final List<TweetMention> mentions; final List<TweetHashtag> hashtags; if (retweet) { tweeter = status.getRetweetedStatus().getUser(); text = status.getRetweetedStatus().getText(); retweeter = status.getUser(); links = readLinks(status.getRetweetedStatus()); mentions = readMentions(status.getRetweetedStatus()); hashtags = readHashtags(status.getRetweetedStatus()); } else { tweeter = status.getUser(); text = status.getText(); links = readLinks(status); mentions = readMentions(status); hashtags = readHashtags(status); }// w w w. ja v a 2 s. c o m final URL profileImageUrl = tweeter.getProfileImageUrlHttps(); final Date createdAt = status.getCreatedAt(); tweet = new Tweet(tweetId, createdAt, tweeter.getScreenName(), tweeter.getName(), profileImageUrl, text, links, mentions, hashtags, retweet, retweet ? retweeter.getScreenName() : null); this.documentDao.add(tweet); } final DocumentUser documentUser = new DocumentUser(tweet, user); if (isAdd || !tweet.getDocumentUsers().contains(documentUser)) { tweet.getDocumentUsers().add(new DocumentUser(tweet, user)); this.documentDao.update(tweet); } } } else { logger.info("Twitter retrieval found no Tweets for user: " + socialConnection.getRemoteUsername()); } twitterSource.setRetrievalDate(new Date()); this.sourceDao.update(twitterSource); }
From source file:com.mycompany.dovetune.PostTweet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a v a 2s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Twitter twitter = (Twitter) request.getSession().getAttribute("twitter"); String tweetItem = request.getParameter("tweet"); String songName = request.getParameter("song"); songName = songName.replace(" ", "_"); String tweet = tweetItem + " #" + songName + " #DoveTune #SoundCloud"; String user = ""; try { Status status = twitter.updateStatus(tweet); user = "<img class='profileImg' src='" + status.getUser().getProfileImageURL() + "' title='Profile Image' alt='Profile Image'><strong>" + status.getUser().getName() + " @" + status.getUser().getScreenName() + "</strong> - " + status.getText(); user = user.replace("#" + songName, "<strong class='hashtags'>#" + songName + "</strong>"); user = user.replace("#DoveTune", "<strong class='hashtags'>#DoveTune</strong>"); user = user.replace("#SoundCloud", "<strong class='hashtags'>#SoundCloud</strong>"); String songL = songName; songL = songL.toLowerCase(); user = user.replace("#" + songL, "<strong class='hashtags'>#" + songL + "</strong>"); } catch (TwitterException ex) { Logger.getLogger(PostTweet.class.getName()).log(Level.SEVERE, null, ex); } // request.setAttribute("tweet", tweet); response.setContentType("text/HTML"); response.getWriter().write(user); // request.getRequestDispatcher("details.jsp").forward(request, response); }