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:com.fsatir.twitter.TwitterManagedBean.java

public List<Media> trendImageList(Twitter twitter, String trendName) {

    Query query = new Query(trendName + " AND filter:images");
    query.setCount(1);//from  w  ww. j ava  2 s  .  com
    QueryResult result;
    try {
        do {
            result = twitter.search(query);

            List<twitter4j.Status> tweets = result.getTweets();
            int counter = 0;
            for (twitter4j.Status status : tweets) {

                Media myMedia = new Media();
                int control = 0;
                for (MediaEntity me : status.getMediaEntities()) {
                    //Tek grsel almay kesinletirmek iin kontrol.
                    //leride modeldeki trendImgURL diziye dntrlerek kontrol kaldrlabilir.
                    if (control < 1)
                        myMedia.setTrendImgURL(me.getMediaURLHttps());
                    control++;
                }
                // URL null deilse, grsel ve bigileri list'e eklenir.
                if (myMedia.getTrendImgURL() != null) {
                    myMedia.setTweetID(status.getId());
                    myMedia.setFavorite_count(status.getFavoriteCount());
                    myMedia.setRetweet_count(status.getRetweetCount());
                    //myMedia.setTrendImgURL(status.getMediaEntities()[0].getMediaURLHttps());
                    myMedia.setTrendName(trendName);
                    myMedia.setName(Long.toString(status.getId()));
                    myMedia.setType(status.getMediaEntities()[0].getType());

                    myMediaList.add(counter++, myMedia);
                }
            }
        } while ((query = result.nextQuery()) != null && result.getRateLimitStatus().getRemaining() > 0);

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

    myMediaListFiltered = filterList(myMediaList);

    return myMediaListFiltered;

}

From source file:com.fuzuapp.model.resultados.TwitterAdapter.java

@Override
public List<Resultado> getResultados(GeoPoint ponto, double raio) {

    List<Resultado> resultados = new ArrayList();
    try {/*from  w ww  .  ja va  2  s .  co  m*/
        Query query = new Query("");
        GeoLocation geo = new GeoLocation(ponto.getLatitude(), ponto.getLongitude());
        query.setGeoCode(geo, raio, Query.KILOMETERS);
        query.resultType(Query.RECENT);
        query.setCount(20);
        QueryResult result = twitter.search(query);

        for (Status status : result.getTweets()) {
            Resultado r = new Resultado();

            r.setDescricao(status.getText());
            r.setUrl("http://twitter.com/statuses/" + String.valueOf(status.getId()));
            r.setNomeUsuario(status.getUser().getName());
            r.setHorario(new SimpleDateFormat("dd/MM HH:mm").format(status.getCreatedAt()));
            r.setFotoUrl(status.getUser().getProfileImageURL());
            //r.setLocal(new GeoPoint(status.getGeoLocation().getLatitude(), status.getGeoLocation().getLongitude()));
            r.setTipo(Resultado.TEXTO);

            resultados.add(r);

        }
    } catch (TwitterException ex) {
        Logger.getLogger(TwitterAdapter.class.getName()).log(Level.SEVERE, null, ex);
    }

    return resultados;
}

From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java

License:Apache License

public static void convertKey(Status status, Struct struct) {
    struct.put("Id", status.getId());
}

From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java

License:Apache License

public static void convert(Status status, Struct struct) {
    struct.put("CreatedAt", status.getCreatedAt()).put("Id", status.getId()).put("Text", status.getText())
            .put("Source", status.getSource()).put("Truncated", status.isTruncated())
            .put("InReplyToStatusId", status.getInReplyToStatusId())
            .put("InReplyToUserId", status.getInReplyToUserId())
            .put("InReplyToScreenName", status.getInReplyToScreenName()).put("Favorited", status.isFavorited())
            .put("Retweeted", status.isRetweeted()).put("FavoriteCount", status.getFavoriteCount())
            .put("Retweet", status.isRetweet()).put("RetweetCount", status.getRetweetCount())
            .put("RetweetedByMe", status.isRetweetedByMe())
            .put("CurrentUserRetweetId", status.getCurrentUserRetweetId())
            .put("PossiblySensitive", status.isPossiblySensitive()).put("Lang", status.getLang());

    Struct userStruct;//w  w w .ja va2  s. c  o  m
    if (null != status.getUser()) {
        userStruct = new Struct(USER_SCHEMA);
        convert(status.getUser(), userStruct);
    } else {
        userStruct = null;
    }
    struct.put("User", userStruct);

    Struct placeStruct;
    if (null != status.getPlace()) {
        placeStruct = new Struct(PLACE_SCHEMA);
        convert(status.getPlace(), placeStruct);
    } else {
        placeStruct = null;
    }
    struct.put("Place", placeStruct);

    Struct geoLocationStruct;
    if (null != status.getGeoLocation()) {
        geoLocationStruct = new Struct(GEO_LOCATION_SCHEMA);
        convert(status.getGeoLocation(), geoLocationStruct);
    } else {
        geoLocationStruct = null;
    }
    struct.put("GeoLocation", geoLocationStruct);
    List<Long> contributers = new ArrayList<>();

    if (null != status.getContributors()) {
        for (Long l : status.getContributors()) {
            contributers.add(l);
        }
    }
    struct.put("Contributors", contributers);

    List<String> withheldInCountries = new ArrayList<>();
    if (null != status.getWithheldInCountries()) {
        for (String s : status.getWithheldInCountries()) {
            withheldInCountries.add(s);
        }
    }
    struct.put("WithheldInCountries", withheldInCountries);

    struct.put("HashtagEntities", convert(status.getHashtagEntities()));
    struct.put("UserMentionEntities", convert(status.getUserMentionEntities()));
    struct.put("MediaEntities", convert(status.getMediaEntities()));
    struct.put("SymbolEntities", convert(status.getSymbolEntities()));
    struct.put("URLEntities", convert(status.getURLEntities()));
}

From source file:com.happy_coding.viralo.twitter.SmartPoster.java

License:Apache License

/**
 * Returns mentions for user.// w ww.  j  a v  a  2 s  .c  o m
 *
 * @return
 */
public List<ContactTweet> getMentions() {

    Twitter twitter = new TwitterFactory().getInstance();

    try {

        ResponseList<Status> mentions = twitter.getMentions();
        List<ContactTweet> contactTweets = new ArrayList<ContactTweet>();

        for (Status status : mentions) {

            Contact contact = new Contact();
            contact.setUid(status.getUser().getId());
            contact.setName(status.getUser().getScreenName());

            ContactTweet contactTweet = new ContactTweet(contact, status.getText());
            contactTweet.setTweetID(status.getId());
            contactTweets.add(contactTweet);
        }
        return contactTweets;

    } catch (TwitterException e) {
        logger.error("can't load mentions", e);
        return null;
    }
}

From source file:com.ibm.TwitterAsyncService.java

License:Open Source License

@Override
public void run() {
    String bookTitle = ac.getRequest().getParameter("title");
    String bookAuthor = ac.getRequest().getParameter("author");
    boolean translate = Boolean.parseBoolean(ac.getRequest().getParameter("enable"));

    logger.debug("Requested book title {} and author {}", bookTitle, bookAuthor);

    Query query = new Query(bookTitle + " " + bookAuthor);
    query.setResultType(Query.RECENT);

    Twitter twitter = TwitterFactory.getSingleton();

    try {/*from  w w  w  .java  2  s  . c  o m*/
        PrintWriter writer = ac.getResponse().getWriter();
        Locale locale = ac.getRequest().getLocale();
        WatsonTranslate watson = new WatsonTranslate(locale);

        // Just get the first page of results to avoid exceeding the Twitter rate limit
        QueryResult result = twitter.search(query);

        Alchemy alchemy = new Alchemy();

        List<Status> tweets = result.getTweets();

        logger.debug("Current tweets {}", tweets.toString());

        for (Status tweetMessage : tweets) {
            JSONObject json = new JSONObject();
            JSONObject tweet = new JSONObject();
            // We need to put the tweet and link into an inner object
            // so that we can use a special formatter in bootstrap table

            json.put("screenName", tweetMessage.getUser().getScreenName());

            if (translate) {
                String message = watson.translate(tweetMessage.getText());
                tweet.put("message", message);
                json.put("sentiment", alchemy.getSentiment(message));
            } else {
                tweet.put("message", tweetMessage.getText());
                json.put("sentiment", alchemy.getSentiment(tweetMessage.getText()));
            }

            String url = "https://twitter.com/" + tweetMessage.getUser().getScreenName() + "/status/"
                    + tweetMessage.getId();

            tweet.put("link", url);

            json.put("tweet", tweet);

            writer.write(("data: " + json.toString() + "\n\n"));
            writer.flush();
        }

        writer.write(("event: finished\n"));
        writer.write(("data: \n\n"));
        writer.flush();
        writer.close();
    } catch (TwitterException e) {
        logger.error("Twitter Error {}", e.getMessage());
    } catch (IOException e) {
        logger.error("could not write SSE {}", e.getMessage());
    } catch (NullPointerException e) {
        logger.error("Exception Twitter Async Service {}", e.getMessage());
    } finally {
        ac.complete();
    }
}

From source file:com.infine.android.devoxx.service.TwitterService.java

License:Apache License

public void triggerRefresh() {
    try {/*w  w w .  j a  va 2  s  . c o m*/
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        long lastTweetId = prefs.getLong(LAST_TWEET_ID, 0);
        Query query = new Query(TWEETS_QUERY);
        if (lastTweetId > 0) {
            query.setSinceId(lastTweetId);
        }
        QueryResult result = mTwitter.search(query);
        Log.i("Twitter", "nombre de tweets recu:" + result.getTweets().size());
        ArrayList<ContentProviderOperation> databaseOps = new ArrayList<ContentProviderOperation>();
        long maxId = 0;
        for (Status status : result.getTweets()) {
            maxId = Math.max(maxId, status.getId());
            databaseOps.add(buildCPOperation(status));
        }
        // batch update
        if (!databaseOps.isEmpty()) {
            mResolver.applyBatch(ScheduleContract.CONTENT_AUTHORITY, databaseOps);
        }
        if (maxId > 0) {
            prefs.edit().putLong(LAST_TWEET_ID, maxId);
        }

    } catch (TwitterException e) {
        // pas de message c'est qui doit pas avoir de reseau
        // Toast.makeText(this, "Erreur durant la rcupration des Tweets",
        // Toast.LENGTH_SHORT).show();
    } catch (RemoteException e) {
        // pas de message
        e.printStackTrace();
    } catch (OperationApplicationException e) {
        // pas de message
        e.printStackTrace();
    }
}

From source file:com.infine.android.devoxx.service.TwitterService.java

License:Apache License

private ContentProviderOperation buildCPOperation(Status tweet) {

    final ContentProviderOperation.Builder builder = ContentProviderOperation
            .newInsert(ScheduleContract.Tweets.CONTENT_URI);

    // affecte les valeurs des colonnes
    builder.withValue(ScheduleContract.Tweets.TWEET_ID, tweet.getId());
    builder.withValue(ScheduleContract.Tweets.CREATION_DATE, tweet.getCreatedAt().getTime());
    builder.withValue(ScheduleContract.Tweets.IMAGE_URL, tweet.getUser().getProfileImageURL());
    builder.withValue(ScheduleContract.Tweets.TEXT, tweet.getText());
    builder.withValue(ScheduleContract.Tweets.USER, tweet.getUser().getName());
    builder.withValue(ScheduleContract.Tweets.USER_NAME, tweet.getUser().getScreenName());

    return builder.build();
}

From source file:com.itbs.aimcer.commune.twitter.TwitterConnection.java

License:Open Source License

/**
 * Update twitter/*from  ww  w.j a v a  2 s . c  o  m*/
 * @param message to update with
 * @return id of the message for a re-tweet
 */
public long setStatus(String message) {
    long result = 0;
    try {
        Status status = connection.updateStatus(message);
        if (status != null) {
            result = status.getId();
        }
    } catch (TwitterException e) {
        notifyErrorOccured("Failed to update status", e);
    }
    notifyStatusChanged();
    return result;
}

From source file:com.itbs.aimcer.commune.twitter.TwitterConnection.java

License:Open Source License

/**
 * Update twitter//  w w  w.j av  a2s .co m
 * @param message to update with
 * @return id of the message for a re-tweet
 */
public long retweetStatus(long message) {
    long result = 0;
    try {
        Status status = connection.retweetStatus(message);
        if (status != null) {
            result = status.getId();
        }
    } catch (TwitterException e) {
        notifyErrorOccured("Failed to update status", e);
    }
    notifyStatusChanged();
    return result;
}