Example usage for twitter4j Status getText

List of usage examples for twitter4j Status getText

Introduction

In this page you can find the example usage for twitter4j Status getText.

Prototype

String getText();

Source Link

Document

Returns the text of the status

Usage

From source file:org.jwebsocket.plugins.twitter.TwitterPlugIn.java

License:Apache License

private void getPublicTimeline(WebSocketConnector aConnector, Token aToken) {
    TokenServer lServer = getServer();//from   www. ja v a 2s .  c o m

    // instantiate response token
    Token lResponse = lServer.createResponse(aToken);
    String lMsg;

    try {
        if (mLog.isDebugEnabled()) {
            mLog.debug("Retreiving public timeline...");
        }
        if (!mCheckAuth(lResponse)) {
            mLog.error(lResponse.getString("msg"));
        } else {
            // return the list of messages as an array of strings...
            List<String> lMessages = new FastList<String>();

            ResponseList lRespList = mTwitter.getPublicTimeline();
            for (int lIdx = 0; lIdx < lRespList.size(); lIdx++) {
                Status lStatus = (Status) lRespList.get(lIdx);
                lMessages.add(lStatus.getText());
            }
            lResponse.setList("messages", lMessages);
            if (mLog.isInfoEnabled()) {
                mLog.info("Public timeline successfully received");
            }
        }
    } catch (Exception lEx) {
        lMsg = lEx.getClass().getSimpleName() + ": " + lEx.getMessage();
        mLog.error(lMsg);
        lResponse.setInteger("code", -1);
        lResponse.setString("msg", lMsg);
    }

    // send response to requester
    lServer.sendToken(aConnector, lResponse);
}

From source file:org.kawalpemilukada.web.controller.SentimentAnalysis.java

private void cariText(JSONArray returnVals, Twitter twitter, String topic) throws ParseException {
    try {/*from   w ww . jav  a 2 s  .co  m*/
        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.komusubi.feeder.sns.twitter.TweetTopic.java

License:Apache License

/**
 * create new instance.//from  w w w  .  java2 s  . c  o  m
 * @param status
 */
public TweetTopic(Status status) {
    this.status = status;
    this.message = new FeederMessage().append(status.getText());
}

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.  j  a v  a 2  s  .  c  o m
    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   ww  w .jav a2  s. c om
        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);
}

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  ww  w.  java2  s.  c o 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.task.CacheUsersStatusesTask.java

License:Open Source License

@SafeVarargs
@Override//from  w w  w .jav a 2s .  c om
protected final Object doInBackground(final TwitterListResponse<twitter4j.Status>... args) {
    if (args == null || args.length == 0)
        return null;
    final ContentResolver resolver = context.getContentResolver();
    final Extractor extractor = new Extractor();

    for (final TwitterListResponse<twitter4j.Status> response : args) {
        if (response == null || response.list == null) {
            continue;
        }
        final List<twitter4j.Status> list = response.list;
        for (int bulkIdx = 0, totalSize = list.size(); bulkIdx < totalSize; bulkIdx += 100) {
            for (int idx = bulkIdx, end = Math.min(totalSize,
                    bulkIdx + ContentResolverUtils.MAX_BULK_COUNT); idx < end; idx++) {
                final twitter4j.Status status = list.get(idx);

                final Set<ContentValues> usersValues = new HashSet<>();
                final Set<ContentValues> statusesValues = new HashSet<>();
                final Set<ContentValues> hashTagValues = new HashSet<>();

                statusesValues.add(createStatus(status, response.accountId));
                for (final String hashtag : extractor.extractHashtags(status.getText())) {
                    final ContentValues values = new ContentValues();
                    values.put(CachedHashtags.NAME, hashtag);
                    hashTagValues.add(values);
                }
                usersValues.add(createCachedUser(status.getUser()));
                if (status.isRetweet()) {
                    usersValues.add(createCachedUser(status.getRetweetedStatus().getUser()));
                }

                bulkInsert(resolver, CachedStatuses.CONTENT_URI, statusesValues);
                bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashTagValues);
                bulkInsert(resolver, CachedUsers.CONTENT_URI, usersValues);
            }
        }
    }

    return null;
}

From source file:org.mariotaku.twidere.util.CacheUsersStatusesTask.java

License:Open Source License

@Override
protected Void doInBackground(final Void... args) {
    if (all_statuses == null || all_statuses.length == 0)
        return null;
    final Extractor extractor = new Extractor();
    final Set<ContentValues> cached_users_values = new HashSet<ContentValues>();
    final Set<ContentValues> cached_statuses_values = new HashSet<ContentValues>();
    final Set<ContentValues> hashtag_values = new HashSet<ContentValues>();
    final Set<Long> user_ids = new HashSet<Long>();
    final Set<Long> status_ids = new HashSet<Long>();
    final Set<String> hashtags = new HashSet<String>();
    final Set<User> users = new HashSet<User>();
    final boolean large_preview_image = Utils
            .getImagePreviewDisplayOptionInt(context) == IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE;

    for (final TwitterListResponse<twitter4j.Status> values : all_statuses) {
        if (values == null || values.list == null) {
            continue;
        }/*  w ww . j a  va2 s.  c  o m*/
        final List<twitter4j.Status> list = values.list;
        for (final twitter4j.Status status : list) {
            if (status == null || status.getId() <= 0) {
                continue;
            }
            status_ids.add(status.getId());
            cached_statuses_values.add(makeStatusContentValues(status, values.account_id, large_profile_image,
                    large_preview_image));
            hashtags.addAll(extractor.extractHashtags(status.getText()));
            final User user = status.getUser();
            if (user != null && user.getId() > 0) {
                users.add(user);
            }
        }
    }

    bulkDelete(resolver, CachedStatuses.CONTENT_URI, CachedStatuses.STATUS_ID, status_ids, null, false);
    bulkInsert(resolver, CachedStatuses.CONTENT_URI, cached_statuses_values);

    for (final String hashtag : hashtags) {
        final ContentValues hashtag_value = new ContentValues();
        hashtag_value.put(CachedHashtags.NAME, hashtag);
        hashtag_values.add(hashtag_value);
    }
    bulkDelete(resolver, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, hashtags, null, true);
    bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashtag_values);

    for (final User user : users) {
        user_ids.add(user.getId());
        cached_users_values.add(makeCachedUserContentValues(user, large_profile_image));
    }
    bulkDelete(resolver, CachedUsers.CONTENT_URI, CachedUsers.USER_ID, user_ids, null, false);
    bulkInsert(resolver, CachedUsers.CONTENT_URI, cached_users_values);
    return 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 {/*from  w  ww  . j a  va  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());
        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;
}