Example usage for twitter4j Status getId

List of usage examples for twitter4j Status getId

Introduction

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

Prototype

long getId();

Source Link

Document

Returns the id of the status

Usage

From source file:org.jclouds.demo.tweetstore.controller.StoreTweetsController.java

License:Apache License

@VisibleForTesting
public void addMyTweets(String contextName, Iterable<Status> responseList) {
    BlobStoreContext context = checkNotNull(contexts.get(contextName),
            "no context for " + contextName + " in " + contexts.keySet());
    BlobMap map = context.createBlobMap(container);
    for (Status status : responseList) {
        Blob blob = null;// w  w w .  ja v  a2  s  . co  m
        try {
            blob = new StatusToBlob(map).apply(status);
            map.put(status.getId() + "", blob);
        } catch (AuthorizationException e) {
            throw e;
        } catch (Exception e) {
            logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context,
                    container);
        }
    }
}

From source file:org.jibble.simplewebserver.RequestThread.java

License:Open Source License

public void run() {
    InputStream reader = null;//from  w w w .j a va 2 s .  c  o  m
    try {
        _socket.setSoTimeout(30000);
        BufferedReader in = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
        BufferedOutputStream out = new BufferedOutputStream(_socket.getOutputStream());

        String request = in.readLine();
        if (request == null || !request.startsWith("GET ")
                || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) {
            // Invalid request type (no "GET")
            sendError(out, 500, "Invalid Method.");
            return;
        }
        String path = request.substring(4, request.length() - 9);

        if (path.indexOf("collection") > -1) {

            Twitter twitter = TF.getInstance();
            try {

                // Uncomment to send tweet and test credentials
                // Status status = twitter.updateStatus("Try this tweet.");

                String id = "custom-549647846786347008";
                int collectionIdIdx = path.indexOf("custom-");
                if (collectionIdIdx > 0) {
                    id = path.substring(collectionIdIdx);
                }
                List<Status> statuses = twitter.getCustomTimeline(id);

                sendHeader(out, 200, "text/html", -1, System.currentTimeMillis());

                String title = "Tweets for '" + id + "'";
                out.write(("<html><head><title>" + title + "</title></head><body><h3>" + title + "</h3><p>\n")
                        .getBytes());

                for (int i = 0; i < statuses.size(); i++) {
                    Status status = statuses.get(i);
                    User user = status.getUser();
                    String blockquote = "<blockquote class=\"twitter-tweet\" lang=\"en\"><p>" + status.getText()
                            + "</p>&mdash; " + user.getName() + " (" + user.getScreenName()
                            + ") <a href=\"https://twitter.com/" + user.getScreenName() + "/status/"
                            + status.getId() + "\">DATE5</a></blockquote>";
                    out.write((blockquote + "<br>\n").getBytes());

                }
                out.write(("</p><hr><p>" + SimpleWebServer.VERSION
                        + "</p><script async src=\"//platform.twitter.com/widgets.js\" charset=\"utf-8\"></script></body><html>")
                                .getBytes());

            } catch (TwitterException e) {
                sendError(out, 500, "Invalid Method.");
            }

            out.flush();
            out.close();

            return;

        }

        File file = new File(_rootDir, URLDecoder.decode(path, "UTF-8")).getCanonicalFile();

        if (file.isDirectory()) {
            // Check to see if there is an index file in the directory.
            File indexFile = new File(file, "index.html");
            if (indexFile.exists() && !indexFile.isDirectory()) {
                file = indexFile;
            }
        }

        if (!file.toString().startsWith(_rootDir.toString())) {
            // Uh-oh, it looks like some lamer is trying to take a peek
            // outside of our web root directory.
            sendError(out, 403, "Permission Denied.");
        } else if (!file.exists()) {
            // The file was not found.
            sendError(out, 404, "File Not Found.");
        } else if (file.isDirectory()) {
            // print directory listing
            if (!path.endsWith("/")) {
                path = path + "/";
            }
            File[] files = file.listFiles();
            sendHeader(out, 200, "text/html", -1, System.currentTimeMillis());
            String title = "Index of " + path;
            out.write(
                    ("<html><head><title>" + title + "</title></head><body><h3>Index of " + path + "</h3><p>\n")
                            .getBytes());
            for (int i = 0; i < files.length; i++) {
                file = files[i];
                String filename = file.getName();
                String description = "";
                if (file.isDirectory()) {
                    description = "&lt;DIR&gt;";
                }
                out.write(("<a href=\"" + path + filename + "\">" + filename + "</a> " + description + "<br>\n")
                        .getBytes());
            }
            out.write(("</p><hr><p>" + SimpleWebServer.VERSION + "</p></body><html>").getBytes());
        } else {
            reader = new BufferedInputStream(new FileInputStream(file));

            String contentType = (String) SimpleWebServer.MIME_TYPES.get(Utils.getExtension(file));
            if (contentType == null) {
                contentType = "application/octet-stream";
            }

            sendHeader(out, 200, contentType, file.length(), file.lastModified());

            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = reader.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
            reader.close();
        }
        out.flush();
        out.close();
    } catch (IOException e) {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception anye) {
                // Do nothing.
            }
        }
    }
}

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.Twitter4j.java

License:Apache License

/**
 * tweet.//from   w  w w.  ja  v a 2 s  .c  o m
 * @param message
 */
public void tweet(Message message) {
    Script current = new ScriptLine("");
    try {
        Status result = null;
        for (Script script : message) {
            current = script; // mark current script for when exception occurred.
            if (outputConsole) {
                System.out.printf("tweet(length:%d): %s%n", TweetScript.lengthAfterTweeted(script.trimedLine()),
                        script.trimedLine());
            } else {
                StatusUpdate status = new StatusUpdate(script.trimedLine());
                if (result != null) {
                    status.inReplyToStatusId(result.getId());
                }
                logger.info("tweet(length:{}): {}", TweetScript.lengthAfterTweeted(status.getStatus()),
                        status.getStatus());
                result = twitter.updateStatus(status);
            }
        }
    } catch (TwitterException e) {
        throw new Twitter4jException(String.format("tweet(length:%d): %s",
                TweetScript.lengthAfterTweeted(current.trimedLine()), current.trimedLine()), e);
    }
}

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;// 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.mariotaku.twidere.loader.support.Twitter4JStatusesLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from ww  w.jav a2  s.c o  m*/
public final List<ParcelableStatus> loadInBackground() {
    final File serializationFile = getSerializationFile();
    final List<ParcelableStatus> data = getData();
    if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) {
        final List<ParcelableStatus> cached = getCachedData(serializationFile);
        if (cached != null) {
            data.addAll(cached);
            if (mComparator != null) {
                Collections.sort(data, mComparator);
            } else {
                Collections.sort(data);
            }
            return new CopyOnWriteArrayList<>(data);
        }
    }
    if (!isFromUser())
        return data;
    final List<Status> statuses;
    final boolean truncated;
    final Context context = getContext();
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
    try {
        final Paging paging = new Paging();
        paging.setCount(loadItemLimit);
        if (mMaxId > 0) {
            paging.setMaxId(mMaxId);
        }
        if (mSinceId > 0) {
            paging.setSinceId(mSinceId - 1);
        }
        statuses = new ArrayList<>();
        final Twitter twitter = getTwitter();
        if (twitter == null) {
            throw new TwitterException("Account is null");
        }
        truncated = truncateStatuses(getStatuses(twitter, paging), statuses, mSinceId);
    } catch (final TwitterException e) {
        // mHandler.post(new ShowErrorRunnable(e));
        Log.w(LOGTAG, e);
        return new CopyOnWriteArrayList<>(data);
    }
    final long minStatusId = statuses.isEmpty() ? -1 : Collections.min(statuses).getId();
    final boolean insertGap = minStatusId > 0 && statuses.size() > 1 && !data.isEmpty() && !truncated;
    mHandler.post(CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(mAccountId, statuses)));
    for (final Status status : statuses) {
        final long id = status.getId();
        final boolean deleted = deleteStatus(data, id);
        data.add(new ParcelableStatus(status, mAccountId, minStatusId == id && insertGap && !deleted));
    }
    final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]);
    for (int i = 0, size = array.length; i < size; i++) {
        final ParcelableStatus status = array[i];
        if (shouldFilterStatus(mDatabase, status) && !status.is_gap && i != size - 1) {
            deleteStatus(data, status.id);
        }
    }
    if (mComparator != null) {
        Collections.sort(data, mComparator);
    } else {
        Collections.sort(data);
    }
    saveCachedData(serializationFile, data);
    return new CopyOnWriteArrayList<>(data);
}

From source file:org.mariotaku.twidere.loader.support.TwitterAPIStatusesLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w  w  w.  ja  v a2s  .c om*/
public final List<ParcelableStatus> loadInBackground() {
    final File serializationFile = getSerializationFile();
    final List<ParcelableStatus> data = getData();
    if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) {
        final List<ParcelableStatus> cached = getCachedData(serializationFile);
        if (cached != null) {
            data.addAll(cached);
            if (mComparator != null) {
                Collections.sort(data, mComparator);
            } else {
                Collections.sort(data);
            }
            return new CopyOnWriteArrayList<>(data);
        }
    }
    if (!isFromUser())
        return data;
    final Twitter twitter = getTwitter();
    if (twitter == null)
        return null;
    final List<Status> statuses;
    final boolean truncated;
    final Context context = getContext();
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
    final boolean noItemsBefore = data == null || data.isEmpty();
    try {
        final Paging paging = new Paging();
        paging.setCount(loadItemLimit);
        if (mMaxId > 0) {
            paging.setMaxId(mMaxId);
        }
        if (mSinceId > 0) {
            paging.setSinceId(mSinceId - 1);
        }
        statuses = new ArrayList<>();
        truncated = truncateStatuses(getStatuses(twitter, paging), statuses, mSinceId);
    } catch (final TwitterException e) {
        // mHandler.post(new ShowErrorRunnable(e));
        Log.w(LOGTAG, e);
        return new CopyOnWriteArrayList<>(data);
    }

    final long[] statusIds = new long[statuses.size()];
    long minId = -1;
    int minIdx = -1;
    int rowsDeleted = 0;
    for (int i = 0, j = statuses.size(); i < j; i++) {
        final twitter4j.Status status = statuses.get(i);
        final long id = status.getId();
        if (minId == -1 || id < minId) {
            minId = id;
            minIdx = i;
        }
        statusIds[i] = id;

        if (deleteStatus(data, status.getId())) {
            rowsDeleted++;
        }
    }

    // Insert a gap.
    final boolean deletedOldGap = rowsDeleted > 0 && ArrayUtils.contains(statusIds, mMaxId);
    final boolean noRowsDeleted = rowsDeleted == 0;
    final boolean insertGap = minId > 0 && (noRowsDeleted || deletedOldGap) && !truncated && !noItemsBefore
            && statuses.size() > 1;
    for (int i = 0, j = statuses.size(); i < j; i++) {
        final Status status = statuses.get(i);
        data.add(new ParcelableStatus(status, mAccountId, insertGap && isGapEnabled() && minIdx == i));
    }

    final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]);
    for (int i = 0, size = array.length; i < size; i++) {
        final ParcelableStatus status = array[i];
        if (shouldFilterStatus(mDatabase, status) && !status.is_gap && i != size - 1) {
            deleteStatus(data, status.id);
        }
    }
    if (mComparator != null) {
        Collections.sort(data, mComparator);
    } else {
        Collections.sort(data);
    }
    saveCachedData(serializationFile, data);
    return new CopyOnWriteArrayList<>(data);
}

From source file:org.mariotaku.twidere.loader.Twitter4JStatusesLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w w w  .j a  va  2s .co  m*/
public final List<ParcelableStatus> loadInBackground() {
    final File serializationFile = getSerializationFile();
    final List<ParcelableStatus> data = getData();
    if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) {
        final List<ParcelableStatus> cached = getCachedData(serializationFile);
        if (cached != null) {
            data.addAll(cached);
            Collections.sort(data);
            return new CopyOnWriteArrayList<ParcelableStatus>(data);
        }
    }
    final List<Status> statuses;
    final boolean truncated;
    final Context context = getContext();
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
    try {
        final Paging paging = new Paging();
        paging.setCount(loadItemLimit);
        if (mMaxId > 0) {
            paging.setMaxId(mMaxId);
        }
        if (mSinceId > 0) {
            paging.setSinceId(mSinceId - 1);
        }
        statuses = new ArrayList<Status>();
        truncated = truncateStatuses(getStatuses(getTwitter(), paging), statuses, mSinceId);
    } catch (final TwitterException e) {
        // mHandler.post(new ShowErrorRunnable(e));
        e.printStackTrace();
        return new CopyOnWriteArrayList<ParcelableStatus>(data);
    }
    final long minStatusId = statuses.isEmpty() ? -1 : Collections.min(statuses).getId();
    final boolean insertGap = minStatusId > 0 && statuses.size() > 1 && !data.isEmpty() && !truncated;
    mHandler.post(CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(mAccountId, statuses)));
    for (final Status status : statuses) {
        final long id = status.getId();
        final boolean deleted = deleteStatus(data, id);
        data.add(new ParcelableStatus(status, mAccountId, minStatusId == id && insertGap && !deleted,
                mHiResProfileImage));
    }
    Collections.sort(data);
    final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]);
    for (int i = 0, size = array.length; i < size; i++) {
        final ParcelableStatus status = array[i];
        if (shouldFilterStatus(mDatabase, status) && !status.is_gap && i != size - 1) {
            deleteStatus(data, status.id);
        }
    }
    saveCachedData(serializationFile, data);
    return new CopyOnWriteArrayList<ParcelableStatus>(data);
}

From source file:org.mariotaku.twidere.loader.Twitter4JStatusLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   w ww  .  j  a  v a 2  s.c  om
public SynchronizedStateSavedList<ParcelableStatus, Long> loadInBackground() {
    final SynchronizedStateSavedList<ParcelableStatus, Long> data = getData();
    List<Status> statuses = null;
    final Context context = getContext();
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int load_item_limit = prefs.getInt(PREFERENCE_KEY_LOAD_ITEM_LIMIT,
            PREFERENCE_DEFAULT_LOAD_ITEM_LIMIT);
    try {
        final Paging paging = new Paging();
        paging.setCount(load_item_limit);
        if (mMaxId > 0) {
            paging.setMaxId(mMaxId);
        }
        if (mSinceId > 0) {
            paging.setSinceId(mSinceId);
        }
        statuses = getStatuses(paging);
    } catch (final TwitterException e) {
        e.printStackTrace();
    }
    if (statuses != null) {
        final boolean insert_gap = load_item_limit == statuses.size() && data.size() > 0;
        final Status min_status = statuses.size() > 0 ? Collections.min(statuses) : null;
        final long min_status_id = min_status != null ? min_status.getId() : -1;
        if (context instanceof Activity) {
            ((Activity) context).runOnUiThread(
                    CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(mAccountId, statuses)));
        }
        for (final Status status : statuses) {
            final long id = status.getId();
            deleteStatus(id);
            data.add(new ParcelableStatus(status, mAccountId,
                    min_status_id > 0 && min_status_id == id && insert_gap, mHiResProfileImage,
                    mLargeInlineImagePreview));
        }
    }
    try {
        final List<ParcelableStatus> statuses_to_remove = new ArrayList<ParcelableStatus>();
        for (final ParcelableStatus status : data) {
            if (isFiltered(mDatabase, status) && !status.is_gap) {
                statuses_to_remove.add(status);
            }
        }
        data.removeAll(statuses_to_remove);
        Collections.sort(data);
    } catch (final ConcurrentModificationException e) {
        Log.w(LOGTAG, e);
    }
    return data;
}

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();
    timestamp = getTime(orig.getCreatedAt());

    final Status retweeted = orig.getRetweetedStatus();
    final User retweet_user = retweeted != null ? orig.getUser() : null;
    is_retweet = orig.isRetweet();/* w  ww.  j  a  v a 2 s. com*/
    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;
}