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:kerguelenpetrel.RespondServlet.java

License:Apache License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    StringBuilder builder = new StringBuilder();
    resp.setContentType("text/plain; charset=UTF-8");

    try {//from   w w w. j  ava2s  .c  o  m
        //Get the Twitter object
        Twitter twit = TwitterFactory.getSingleton();
        ResponseList<Status> mentions = twit.getMentionsTimeline();

        lastPostIdEntity = datastore.get(KeyFactory.createKey("lastPostIDEntity", "ID"));
        lastPostId = Long.parseLong(lastPostIdEntity.getProperty("lastPostID").toString());

        if (mentions.size() == 0) {
            resp.getWriter().println("No mentions so far...\n");
            return;
        }

        for (Status mention : mentions) {
            if (lastPostId < mention.getId()) {
                if (mention.getUser().getId() == twit.getId())
                    ; //don't respond to myself

                else if (mention.isRetweeted())
                    mention = twit.createFavorite(mention.getId()); //mark the retweet as a favourite
                else if (mention.getText().toLowerCase().contains("bye")) {
                    builder.setLength(0);
                    builder.append("@");
                    builder.append(mention.getUser().getScreenName());
                    builder.append(" Bye");
                } else {
                    builder.setLength(0);
                    //Add the screen name of the person we are responding to
                    builder.append("@");
                    builder.append(mention.getUser().getScreenName() + " ");

                    //Get feed title as content
                    builder.append(getFeedTitle(resp));

                    //Get a Wordnik trend
                    builder.append(getWordnikTrend(resp));

                    /* Tweets are maximum 280 characters */
                    if (builder.length() > 280) {
                        builder.setLength(builder.lastIndexOf(" ", 270));
                        builder.append(end[(r.nextInt(end.length))]);
                    }
                }
                //Set the status
                StatusUpdate status = new StatusUpdate(builder.toString());

                //Post the status
                twit.updateStatus(status);
                resp.getWriter().println("Tweet posted: " + status.getStatus());
            }
        }
        //Save last post ID
        lastPostIdEntity.setProperty("lastPostID", (Long.toString(mentions.get(0).getId())));
        datastore.put(lastPostIdEntity);
    } catch (EntityNotFoundException e) {
        // Make new ResponseIDentity
        lastPostIdEntity = new Entity("lastPostIDEntity", "ID");
        lastPostIdEntity.setProperty("lastPostID", "0");
        datastore.put(lastPostIdEntity);
        resp.getWriter()
                .println("Made new lastPostId " + lastPostIdEntity.getProperty("lastPostID").toString());
    } catch (TwitterException e) {
        resp.getWriter().println("Problem with Twitter \n");
        e.printStackTrace(resp.getWriter());
    }
}

From source file:kr.debop4j.search.twitter.Twitters.java

License:Apache License

public static Twit createTwit(Status status) {
    Twit twit = new Twit();
    twit.setId(status.getId());
    twit.setUsername(status.getUser().getName());
    twit.setText(status.getText());/*from w  w  w .  j a  v a2 s .  c  o m*/
    twit.setCreatedAt(status.getCreatedAt());
    return twit;
}

From source file:moderation.Moderate.java

public List getTwitterpost() {

    List posts = new ArrayList();
    try {/*ww  w.ja  va2 s  .c  om*/
        List savedpost = getSavedList(album_id);
        String tagname = this.hash;
        Twitter twitter = setting.TwitterToken.twitterObject();
        Query query = new Query(tagname);
        query.setCount(50);
        QueryResult result;
        result = twitter.search(query);
        List<Status> tweets = result.getTweets();
        for (Status tweet : tweets) {
            System.out.println("\n\n\n" + tweet);
            PostModel post = new PostModel();
            post.setAlbum_id(this.album_id);
            if (savedpost.contains(tweet.getId()))
                post.setStatus("old");
            else
                post.setStatus("new");
            post.setPost_id("" + tweet.getId());
            post.setSender_name(URLEncoder.encode(tweet.getUser().getScreenName(), "UTF-8"));
            post.setCaption_text(URLEncoder.encode(tweet.getText(), "UTF-8"));
            post.setSender_pic(tweet.getUser().getProfileImageURL());
            post.setSender_id("" + tweet.getUser().getId());

            for (MediaEntity mediaEntity : tweet.getMediaEntities()) {
                post.setImage_standard(mediaEntity.getMediaURL());
                post.setImage_low(mediaEntity.getMediaURL());
            }
            post.setPost_time(tweet.getCreatedAt().toString());
            post.setType("twitter_post");
            post.setLink(null);
            post.setParam("post_id=" + post.getPost_id() + "&album_id=" + post.getAlbum_id() + "&type="
                    + post.getType() + "&post_time=" + post.getPost_time() + "&link=" + post.getLink()
                    + "&pic_low=" + post.getImage_low() + "&pic_standard=" + post.getImage_standard()
                    + "&post_message=" + post.getCaption_text() + "&sender_name=" + post.getSender_name()
                    + "&sender_id=" + post.getSender_id() + "&sender_pic=" + post.getSender_pic());

            posts.add(post);

        }
        this.twitternext = result.nextQuery();

    } catch (Exception e) {
        System.err.println("Exception occure in getTwitter " + e);
    }

    return posts;
}

From source file:module.backoffice.Retweet.java

@Override
public boolean execute(Object... object) {
    PandaProdApplication application = PandaProdApplication.getApplication();
    User user = application.getUser();/*ww  w  .  ja v  a  2 s. c  o  m*/

    try {
        JList jlist = (JList) application.getMainFrameJComponent("jListTweet");
        Status status = (Status) jlist.getSelectedValue();
        user.getTwitter().retweetStatus(status.getId());
    } catch (TwitterException ex) {
        Logger.getLogger(SendTweet.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, "Impossible de retweeter ce tweet.", "Retweet impossible",
                JOptionPane.ERROR_MESSAGE);

        return false;
    }
    user.loadNumber();
    user.loadTimeLine();
    JOptionPane.showMessageDialog(null, "Le retweet c'est envol ! ", "retweet envoy",
            JOptionPane.INFORMATION_MESSAGE);

    return true;
}

From source file:monitoring.tools.TwitterAPI.java

License:Apache License

private void generateData(String searchTimeStamp) {

    List<MonitoringData> data = new ArrayList<>();
    for (Status s : tweetInfo) {
        String id = String.valueOf(s.getId());
        String timeStamp = String.valueOf(s.getCreatedAt());
        String message = s.getText();
        String author = "@" + s.getUser().getScreenName();
        String link = "https://twitter.com/" + s.getUser().getName().replace(" ", "") + "/status/" + s.getId();
        MonitoringData dataObj = new MonitoringData(id, timeStamp, message, author, link);
        data.add(dataObj);//from   w w  w  .ja v a2s.  c o  m
    }
    tweetInfo = new ArrayList<>();
    //kafka.generateResponseKafka(data, searchTimeStamp, id, configurationId, this.confParams.getKafkaTopic);
    kafka.generateResponseIF(data, searchTimeStamp, id, configurationId, this.confParams.getKafkaTopic());
    logger.debug("Data successfully sent to Kafka endpoint");
    ++id;
}

From source file:net.bluemix.droneselfie.TwitterUtilities.java

License:Open Source License

private String tweet(String pictureId, String message) {
    String output = null;//w  w  w . j  a  v  a2  s .  c  om
    if (message == null)
        return null;
    if (message.equalsIgnoreCase(""))
        return null;

    try {
        String consumerKey = ConfigUtilities.getSingleton().getTwitterConsumerKey();
        String consumerSecret = ConfigUtilities.getSingleton().getTwitterConsumerSecret();
        String accessToken = ConfigUtilities.getSingleton().getTwitterAccessToken();
        String accessTokenSecret = ConfigUtilities.getSingleton().getTwitterAccessTokenSecret();

        TwitterFactory twitterFactory = new TwitterFactory();
        Twitter twitter = twitterFactory.getInstance();
        twitter.setOAuthConsumer(consumerKey, consumerSecret);
        twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

        StatusUpdate statusUpdate = new StatusUpdate(message);

        AttachmentInputStream data = DatabaseUtilities.getSingleton().getDB().getAttachment(pictureId,
                pictureId);
        statusUpdate.setMedia("picture", data);

        Status status = twitter.updateStatus(statusUpdate);
        if (status == null)
            return null;
        output = "https://twitter.com/bluedroneselfie/status/" + String.valueOf(status.getId());

        return output;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return output;
}

From source file:net.bluemix.newsaggregator.TwitterUtilities.java

License:Open Source License

private String tweet(String message) {
    String output = null;/*from   w w w  . ja v  a 2s .  c om*/
    if (message == null)
        return null;
    if (message.equalsIgnoreCase(""))
        return null;

    try {
        String consumerKey = ConfigUtilities.getSingleton().getTwitterConsumerKey();
        String consumerSecret = ConfigUtilities.getSingleton().getTwitterConsumerSecret();
        String accessToken = ConfigUtilities.getSingleton().getTwitterAccessToken();
        String accessTokenSecret = ConfigUtilities.getSingleton().getTwitterAccessTokenSecret();

        TwitterFactory twitterFactory = new TwitterFactory();
        Twitter twitter = twitterFactory.getInstance();
        twitter.setOAuthConsumer(consumerKey, consumerSecret);
        twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

        StatusUpdate statusUpdate = new StatusUpdate(message);

        Status status = twitter.updateStatus(statusUpdate);
        if (status == null)
            return null;
        output = "https://twitter.com/BluemixInfo/status/" + String.valueOf(status.getId());

        return output;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return output;
}

From source file:net.lacolaco.smileessence.command.status.StatusCommandCongratulate.java

License:Open Source License

public String build() {
    Status status = getOriginalStatus();
    int favCount;
    Random rand = new Random();
    int r = rand.nextInt(100);
    if (r < 50) {
        favCount = 50;//from   www .j ava2s  . c  om
    } else if (r < 80) {
        favCount = 100;
    } else if (r < 90) {
        favCount = 250;
    } else if (r < 99) {
        favCount = 1000;
    } else {
        favCount = 10000;
    }
    return String.format("@%s Congrats on your %s  tweet! http://favstar.fm/t/%s",
            status.getUser().getScreenName(), favCount, status.getId());
}

From source file:net.lacolaco.smileessence.command.status.StatusCommandCongratulate.java

License:Open Source License

@Override
public boolean execute() {
    Status status = getOriginalStatus();
    StatusUpdate update = new TweetBuilder().setText(build()).setInReplyToStatusID(status.getId()).build();
    Twitter twitter = new TwitterApi(account).getTwitter();
    new TweetTask(twitter, update, getActivity()).execute();
    new FavoriteTask(twitter, status.getId(), getActivity()).execute();
    return true;/* www.j a  v  a  2s  .c om*/
}

From source file:net.lacolaco.smileessence.data.FavoriteCache.java

License:Open Source License

/**
 * Put status into cache/*from  w w w  . j  a  v  a  2 s .co  m*/
 */
public void put(Status status) {
    if (!status.isRetweet()) {
        cache.put(status.getId(), status.isFavorited());
    }
}