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.tomitribe.chatterbox.twitter.adapter.TwitterResourceAdapter.java

License:Apache License

private void replyTo(final Status status, final String reply, final boolean prefix) throws TwitterException {
    final String message;

    if (prefix) {
        message = "@" + status.getUser().getScreenName() + " " + reply;
    } else {//from   www .  j a  va 2 s. co  m
        message = reply;
    }

    final StatusUpdate statusUpdate = new StatusUpdate(message);
    statusUpdate.setInReplyToStatusId(status.getId());
    twitter.updateStatus(statusUpdate);
}

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 a v a2  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.model.TwitterStatuses.java

License:Apache License

public void add(ResponseList<twitter4j.Status> statuses, AddUserCallback addUserCallback) {

    TwitterStatus firstItem = size() > 0 ? get(0) : null;
    int addCount = 0;

    boolean stillMore = true;
    TwitterStatus lastAddedStatus = null;

    mGetNewStatusesMaxId = null;/*from   w ww  .ja va2  s  . c o  m*/

    for (Status status : statuses) {
        if (firstItem != null && status.getId() == firstItem.mId) {
            stillMore = false;
            break;
        }

        lastAddedStatus = new TwitterStatus(status);
        add(lastAddedStatus);

        if (addUserCallback != null) {
            addUserCallback.addUser(status.getUser());
            if (status.isRetweet()) {
                Status retweetedStatus = status.getRetweetedStatus();
                if (retweetedStatus != null) {
                    addUserCallback.addUser(retweetedStatus.getUser());
                }
            }
        }

        addCount += 1;
    }

    if (stillMore && lastAddedStatus != null) {
        mGetNewStatusesMaxId = lastAddedStatus.mId;
    }

    if (addCount > 0) {
        sort();
    }
}

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  w w w.  j a v a2s. 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.wandora.application.tools.extractors.twitter.AbstractTwitterExtractor.java

License:Open Source License

public Topic reifyTweet(Status t, TopicMap tm) {
    Topic tweetTopic = null;/* ww w . j  a va  2 s.  c  o  m*/
    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.cep.uima.demo.TweetExtractor.java

License:Open Source License

/***
 *
 *///from  w  w  w  .j ava2s  . c  o m
private void retrieveTweets(int maxTweets) {

    Paging paging;

    // set the lowest value of the tweet ID initially to one less than Long.MAX_VALUE
    long min_id = Long.MAX_VALUE - 1;
    int count = 0;
    int index = 0;
    boolean maxValueReached = false;

    logger.info("Started Extracting Tweets of user: " + userToSearch);
    // iterate through the timeline untill the iteration returns no tweets

    while (true) {
        try {

            //count = tweetList.size();

            // paging tweets at a rate of 100 per page
            paging = new Paging(1, 100);

            // if this is not the first iteration set the new min_id value for the page
            if (count != 0) {
                logger.info("Extracted Tweet Count : " + count);
                paging.setMaxId(min_id - 1);
            }

            // get a page of the tweet timeline with tweets with ids less than the min_id value
            List<Status> tweetTempList = twitterApp.getUserTimeline(userToSearch, paging);

            // iterate the results and add to tweetList
            for (Status s : tweetTempList) {
                if (count == maxTweets) {
                    maxValueReached = true;
                    break;
                }
                count++;
                Tweet tweet = new Tweet(s.getId(), s.getCreatedAt(), s.getText());
                tweetList.add(tweet);
                logger.debug(" " + (index++) + " " + tweet.toString());

                // set the value for the min value for the next iteration
                if (s.getId() < min_id) {
                    min_id = s.getId();
                }
            }

            // if the results for this iteration is zero, means we have reached the API limit or we have extracted the maximum
            // possible, so break
            if (tweetTempList.size() == 0 || maxValueReached) {
                break;
            }

        } catch (TwitterException e) {
            e.printStackTrace();
            break;
        } catch (Exception e) {
            e.printStackTrace();
            break;
        }
    }

}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(Status t) throws XMLStreamException {
    startElement("tweet");
    attribute("id", t.getId());

    // write("annotations",t.getAnnotations());
    write("created-at", t.getCreatedAt());
    write("from-user", sanitizeID(t.getUser().getId()), sanitizeUser(t.getUser().getName()));
    write("geo-location", t.getGeoLocation());
    write("hash-tags", t.getHashtagEntities());
    write("iso-language-code", t.getUser().getLang());
    write("location", t.getUser().getLocation());
    write("media", t.getMediaEntities());
    write("place", t.getPlace());
    write("profile-image-url", sanitizeUser(t.getUser().getProfileImageURL()));
    write("source", t.getSource());
    write("text", t.getText());
    write("to-user", sanitizeID(t.getInReplyToUserId()), sanitizeUser(t.getInReplyToScreenName()));
    write("url-entities", t.getURLEntities());
    write("user-mention-entities", t.getUserMentionEntities());

    endElement();/*w  w w  .j  av a2s .com*/

}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(String localName, Status status) throws XMLStreamException {
    if (status != null) {
        startElement(localName);/* w ww.  j a  v  a  2 s. c o  m*/
        attribute("id", status.getId());

        // write("annotations",t.getAnnotations());
        write("created-at", status.getCreatedAt());

        write("user", status.getUser());
        write("geo-location", status.getGeoLocation());
        write("hash-tags", status.getHashtagEntities());

        write("media", status.getMediaEntities());
        write("place", status.getPlace());

        write("source", status.getSource());
        write("text", status.getText());

        write("url-entities", status.getURLEntities());
        write("user-mention-entities", status.getUserMentionEntities());

        endElement();
    }
}

From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java

License:Open Source License

/**
 * create an item by his twitter Status description, will add hashtags and others "metas"
 * @param s the twitter Status/*from w ww.  j  a v  a 2  s  .co m*/
 * @param source the Uri of the source
 * @return the item created
 */
private static Item getItemFromStatus(Status s, String source) {
    String text = s.getText();
    if (s.isRetweet()) {
        text = s.getRetweetedStatus().getText();
    }
    Item res = new Item(source,
            "https://twitter.com/" + s.getUser().getScreenName() + "/status/" + Long.toString(s.getId()), text,
            text, s.getCreatedAt());
    String[] hashtags = getHashTags(res.getDescription());
    for (String hashtag : hashtags) {
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_HASHTAG, hashtag, true, true));
    }
    for (String mentioned : TwitterApi.extractor.extractMentionedScreennames(s.getText())) {
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_MENTIONED, "@" + mentioned, true, true));
    }
    if (s.getGeoLocation() != null) {
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LONGITUDE,
                Double.toString(s.getGeoLocation().getLongitude()), true, true));
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LATITUDE,
                Double.toString(s.getGeoLocation().getLatitude()), true, true));
    }
    res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_AUTHOR, "@" + s.getUser().getScreenName(), true, true));
    return res;
}

From source file:Principal.Tracker_Twitter.java

License:Minecraft Mod Public

public void guardarResultados_Twitter(List<ObjetoBuscar> lista, BD base, int contadorBase, int TokenIndice)
        throws NoSuchAlgorithmException, KeyManagementException {
    int nuevoContadorBase = 0;
    if (contadorBase >= lista.size()) {
        System.out.println("Termino en:" + contadorBase);
    } else {//from w ww  . j  ava  2 s. c o  m
        System.out.println("---------------------------------------------------------------------:P");

        TrustManager[] trustAllCerts = { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };
        SSLContext sc = SSLContext.getInstance("SSL");

        sc.init(null, trustAllCerts, new SecureRandom());

        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

        System.out.println("Token : " + TokenIndice);
        System.out.println(consumerKey[TokenIndice]);
        try {
            ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setOAuthConsumerKey(consumerKey[TokenIndice]);
            cb.setOAuthConsumerSecret(this.consumerSecret[TokenIndice]);
            cb.setOAuthAccessToken(this.token[TokenIndice]);
            cb.setOAuthAccessTokenSecret(this.tokenSecret[TokenIndice]);
            Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance();

            for (int numtTweets = contadorBase; numtTweets < contadorBase + 5; numtTweets++) {

                if (((ObjetoBuscar) lista.get(numtTweets)).getUrl().equals("")
                        || ((ObjetoBuscar) lista.get(numtTweets)).getUrl() == null) {

                } else {

                    System.out.println("Usuario:  " + ((ObjetoBuscar) lista.get(numtTweets)).getUrl());

                    String usuariosinArroba = ((ObjetoBuscar) lista.get(numtTweets)).getUrl().replace("@", "");

                    System.out.println("" + usuariosinArroba);

                    try {

                        User usuario = unauthenticatedTwitter.showUser(usuariosinArroba);
                        List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe();
                        List<Status> favoritos = unauthenticatedTwitter.getFavorites();
                        Paging paging = new Paging(1, 1000);
                        ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(),
                                paging);
                        System.out.println("Followers: " + usuario.getFollowersCount());
                        System.out.println("Yo sigo: " + usuario.getFriendsCount());
                        List<String> listaTweets = new ArrayList();
                        List<Long> ListaRettewts = new ArrayList();
                        List<Integer> ListaFavoritos = new ArrayList();
                        List<Integer> ListaMenciones = new ArrayList();
                        List<Date> ListaFecha = new ArrayList();
                        List<Long> ListaIds = new ArrayList();
                        for (Status sta : statuses) {
                            ListaIds.add(Long.valueOf(sta.getId()));
                            listaTweets.add(sta.getText());
                            ListaRettewts.add(Long.valueOf(Long.parseLong(sta.getRetweetCount() + "")));
                            ListaMenciones.add(Integer.valueOf(sta.getUserMentionEntities().length));
                            ListaFecha.add(sta.getCreatedAt());
                            ListaFavoritos.add(Integer.valueOf(sta.getFavoriteCount()));
                        }
                        for (int i = 0; i < listaTweets.size(); i++) {
                            base.guardarTrackTwitter_Log((Long) ListaIds.get(i),
                                    ((ObjetoBuscar) lista.get(numtTweets)).getUrl(),
                                    (String) listaTweets.get(i), (Date) ListaFecha.get(i),
                                    (Long) ListaRettewts.get(i), ((Integer) ListaFavoritos.get(i)).intValue(),
                                    ((Integer) ListaMenciones.get(i)).intValue());
                        }

                    } catch (Exception e) {
                        System.err.println("Entro al Try por :" + e);
                    }

                    nuevoContadorBase = numtTweets;
                }
            }
            System.out.println("Numero de Contador Base:" + nuevoContadorBase);
            guardarResultados_Twitter(lista, base, nuevoContadorBase + 1, TokenIndice + 1);
        } catch (NumberFormatException e) {
            System.err.println("Fallo por :" + e);
        }
    }
}