Example usage for twitter4j StatusDeletionNotice getStatusId

List of usage examples for twitter4j StatusDeletionNotice getStatusId

Introduction

In this page you can find the example usage for twitter4j StatusDeletionNotice getStatusId.

Prototype

long getStatusId();

Source Link

Usage

From source file:gov.nasa.jpl.memex.elwha.impl.ElwhaResource.java

License:Apache License

/**
 * Main entry of this application./*from  ww w.j a v a  2s  .c o m*/
 *
 * @param userIds follow(comma separated user ids) track(comma separated filter terms)
 * @throws TwitterException when Twitter service or network is unavailable
 * @return
 */
@Override
public Elwha get(String userIds) {
    //return new Elwha().setMessage("Hello, Rest.li!");
    // }

    //if (userIds.length < 1) {
    //  System.out.println("Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]");
    //  System.exit(-1);
    //}

    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addListener(listener);
    ArrayList<Long> follow = new ArrayList<Long>();
    ArrayList<String> track = new ArrayList<String>();
    if (isNumericalArgument(userIds)) {
        for (String id : userIds.split(",")) {
            follow.add(Long.parseLong(id));
        }
    } else {
        track.addAll(Arrays.asList(userIds.split(",")));
    }
    long[] followArray = new long[follow.size()];
    for (int i = 0; i < follow.size(); i++) {
        followArray[i] = follow.get(i);
    }
    String[] trackArray = track.toArray(new String[track.size()]);

    // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
    twitterStream.filter(new FilterQuery(0, followArray, trackArray));

    return new Elwha().setUserIds("Mock stub!");
}

From source file:kafka.producer.PrintGeoStream.java

License:Apache License

/**
 * Main entry of this application.// ww w  .j  a v a 2s .co  m
 *
 * @param args <kafka host> <kafka topic>
 * @throws twitter4j.TwitterException
 */
public static void main(String[] args) throws TwitterException {

    //        if (args.length != 2) {
    //            System.out.println("Usage: java twitter4j.examples.PrintFilterStream  <kafka host>  <kafka topic>");
    //            System.exit(-1);
    //        }

    //        final String kafkaZKHost = args[0];
    //        final String kafkaTopic = args[1];

    final String kafkaZKHost = "localhost";
    final String kafkaTopic = "flightDelay";

    BasicConfigurator.configure();

    StatusListener listener = new StatusListener() {

        Gson gson = new Gson();

        Properties kafkaProps = new Properties();
        //kafkaProps.put("serializer.class", "kafka.serializer.StringEncoder");
        //kafkaProps.put("zk.connect", "localhost:2181");
        Producer<Integer, String> kafkaProducer = null;
        int tweetCount = 0;
        int interimCount = 0;

        @Override
        public void onStatus(Status status) {
            if (kafkaProducer == null) {
                kafkaProps.put("serializer.class", "kafka.serializer.StringEncoder");
                //kafkaProps.put("zk.connect", "localhost:2181");
                kafkaProps.put("zk.connect", kafkaZKHost.concat(":2181"));
                kafkaProducer = new Producer<Integer, String>(new ProducerConfig(kafkaProps));

            }
            tweetCount++;
            interimCount++;
            if (interimCount == 100) {
                LOG.info(" total tweets received: " + tweetCount);
                interimCount = 0;
            }

            //System.out.println("@" + status.getUser().getScreenName() + " - "); // + status.getText());
            //if ( status.getPlace() != null ) {
            //    System.out.println("coordinates = " + status.getPlace().getGeometryCoordinates());
            //}

            TweetInfo tweetInfo = new TweetInfo();
            tweetInfo.populate(status);
            String message = gson.toJson(tweetInfo, TweetInfo.class);

            kafkaProducer.send(new ProducerData<Integer, String>(kafkaTopic, message));
            //kafkaProducer.send(new ProducerData<Integer, String>("live_tweets", message));
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            //System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };
    /*
     * - use Redis to pass filter messages in - or ZK?
     * - Read in filter JSON with parms for:
     *     - lat/lon boxj
     *     - screen names to follow
     *     - hashtags to track
     * - Convert screen names to userIds
     *     - Twitter twitter = new TwitterFactory().getInstance();
     *       ResponseList<User> users = twitter.lookupUsers(args[0].split(","));
     * - Kick off filter with new FilterQuery
     *     - periodically check, and if filter updated, restart the TwitterStream:
     *         .shutdown()
     *         new
     *         .addListener
     * 
     * 
     */

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    //        twitterStream.setOAuthAccessToken(new AccessToken("14098069-IgutahzmbaCubdoMU0MxsfsJT2iNVpRnoohCbV67k", "d1kFKqRSnrlA4bP1XWWLiHNsHfYDZQPWDHRVpGP4hM"));
    //        twitterStream.setOAuthConsumer("G0SKTmMXjfMsunBh3Furg", "iVTYNLqVaVdUZz4xOn7H8ywylTaTuW3kH1dT21NUy4");
    twitterStream.addListener(listener);
    /*
     * For CONUS only: 
     *  "lowerLat": "22.0",
     *  "lowerLon": "-127.0",
     *  "upperLat": "47.5",
     *  "upperLon": "-67.0"
     */
    FilterQuery fQuery = new FilterQuery();
    String[] topics = new String[2];
    topics[0] = "delayed flight";
    topics[1] = "flight delay";

    //        double[][] us = {{-180, 24}, {-66, 50}};
    double[][] lax = { { -118.5, 33.8 }, { -118.3, 34.01 } };
    fQuery.locations(lax);
    fQuery.track(topics);
    twitterStream.filter(fQuery);

}

From source file:net.lacolaco.smileessence.twitter.UserStreamListener.java

License:Open Source License

@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
    for (CustomListAdapter<?> adapter : activity.getListAdapters()) {
        if (adapter != null && adapter instanceof StatusListAdapter) {
            StatusListAdapter statusListAdapter = (StatusListAdapter) adapter;
            statusListAdapter.removeByStatusID(statusDeletionNotice.getStatusId());
            statusListAdapter.updateForce();
        }//  w  w  w . j  av a 2 s.  co m
    }
    StatusCache.getInstance().remove(statusDeletionNotice.getStatusId());
}

From source file:net.nokok.twitduke.core.twitter.PrintUserStreamListener.java

License:Open Source License

@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
    System.out.println("onDeletionNoticeStatus: " + statusDeletionNotice.getStatusId());
}

From source file:org.primeoservices.cfgateway.twitter.TwitterUserStream.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public void onDeletionNotice(final StatusDeletionNotice statusDeletionNotice) {
    final Struct data = RailoUtils.createStruct();
    data.put("statusId", statusDeletionNotice.getStatusId());
    data.put("userId", statusDeletionNotice.getUserId());
    this.invokeListener("onDeletionNotice", data);
}

From source file:org.socialsketch.tool.rubbish.experiments.PrintSampleStream.java

License:Apache License

/**
 * Main entry of this application.//from w  w w .  jav  a2  s.c  o  m
 *
 * @param args
 */
public static void main(String[] args) throws TwitterException {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };
    twitterStream.addListener(listener);
    twitterStream.sample();
    //twitterStream.
}

From source file:org.socialsketch.tool.rubbish.twitterstream.PrintFilterStream.java

License:Apache License

/**
 * Main entry of this application.//from w  w  w  . j  a  v  a 2  s .co m
 *
 * @param args follow(comma separated user ids) track(comma separated filter terms)
 * @throws twitter4j.TwitterException
 */
public static void main(String[] args) throws TwitterException {
    //        if (args.length < 1) {
    //            System.out.println("Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]");
    //            System.exit(-1);
    //        }

    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addListener(listener);

    ArrayList<Long> follow = new ArrayList<Long>();
    ArrayList<String> track = new ArrayList<String>();

    //        for (String arg : args) {
    //            if (isNumericalArgument(arg)) {
    //                for (String id : arg.split(",")) {
    //                    follow.add(Long.parseLong(id));
    //                }
    //            } else {
    //                track.addAll(Arrays.asList(arg.split(",")));
    //            }
    //        }
    track.add("void setup draw");
    track.add("void size");

    long[] followArray = new long[follow.size()];
    for (int i = 0; i < follow.size(); i++) {
        followArray[i] = follow.get(i);
    }

    String[] trackArray = track.toArray(new String[track.size()]);

    // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
    twitterStream.filter(new FilterQuery(0, followArray, trackArray));
}

From source file:SentimentAnalyses.PrintSampleStream.java

License:Apache License

public static void main(String[] args) throws TwitterException {

    final PrintSampleStream pr = new PrintSampleStream();

    try {/*from www .  jav  a 2s  .com*/
        pr.LinkMongodb();
    } catch (Exception e) {
        e.printStackTrace();
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("Em3WTI7jc90HcvKzPkTLQ")
            .setOAuthConsumerSecret("vg4p6rOF32bmffqRR8m0jAUClrxvtGiMB5PrSr3Zsw")
            .setOAuthAccessToken("1681973072-1q0zI0VPjHD3ttNuaBOL94frzCI9sXInxAcDK0w")
            .setOAuthAccessTokenSecret("ZRLkOyjmhHBkU1iNyEVNyIgIBsKrl0DUDKOcOMneYFYEM");
    cb.setJSONStoreEnabled(true);

    TwitterStreamFactory tf = new TwitterStreamFactory(cb.build());
    TwitterStream twitterStream = tf.getInstance();
    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            //System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            //System.out.println(status);
            String str = DataObjectFactory.getRawJSON(status);
            try {
                //JSONObject nnstr = new JSONObject(newstr);
                DBObject dbObject = (DBObject) JSON.parse(str);
                //                    System.out.println(dbObject);
                pr.collection.insert(dbObject);
                //System.out.println(dbObject);
                pr.count++;
                if (pr.count % 1000 == 0)
                    System.out.println(pr.count);
                if (pr.count > 100000) {
                    pr.mongo.close();
                    System.exit(0);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };
    twitterStream.addListener(listener);

    String[] trackArray;
    String[] Track = { "Malaysia Airlines", "Flight MH370", "Boeing-777", "Kuala Lumpur", "Bei jing" };
    //trackArray[0] = "Obama";
    //trackArray[1] = "Romney";

    FilterQuery filter = new FilterQuery();
    filter.track(Track);
    String[] lang = { "en" };
    filter.language(lang);
    twitterStream.filter(filter);
    //pr.mongo.close();
}

From source file:stream.PrintSampleStream.java

License:Apache License

/**
 * Main entry of this application.//from ww w.j av  a  2  s .  co  m
 *
 * @param args
 */
public static void main(String[] args) throws TwitterException {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    StatusListener listener = new StatusListener() {
        public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };
    twitterStream.addListener(listener);
    twitterStream.sample();
}

From source file:Twitter.FilterStream.java

License:Apache License

public static void main(String[] args) throws TwitterException {

    System.getProperties().put("http.proxyHost", "127.0.0.1");
    System.getProperties().put("http.proxyPort", "8580");

    /* if (args.length < 1) {
    System.out.println("Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]");
    System.exit(-1);/* www.j a  v  a  2s.  com*/
     }*/

    final FilterStream fs = new FilterStream();

    try {
        fs.LinkMongodb();
    } catch (Exception e) {
        e.printStackTrace();
    }

    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            String str = DataObjectFactory.getRawJSON(status);
            try {
                //JSONObject nnstr = new JSONObject(newstr);  
                DBObject dbObject = (DBObject) JSON.parse(str);
                fs.collection.insert(dbObject);
                //System.out.println(dbObject);  
                fs.count++;
                if (fs.count > 900000000) {
                    fs.mongo.close();
                    System.exit(0);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("7ZVgfKiOvBDcDFpytRWSA")
            .setOAuthConsumerSecret("JmeJVeym78arzmGthrDUshQyhkq6nWA9tWLUKxc")
            .setOAuthAccessToken("321341780-Zy7LptVYBZBVvAeQ5GFJ4aKFw8sdqhWBnvA3pDuO")
            .setOAuthAccessTokenSecret("foi8FnQCeN0J5cdwad05Q6d7dbytFayQn1ZOvmhF6Qc");
    cb.setJSONStoreEnabled(true);

    TwitterStreamFactory tf = new TwitterStreamFactory(cb.build());

    TwitterStream twitterStream = tf.getInstance();
    twitterStream.addListener(listener);
    ArrayList<Long> follow = new ArrayList<Long>();
    ArrayList<String> track = new ArrayList<String>();

    //String[] keywords = {"RT @justinbieber"};
    String[] keywords = { "27260086" }; // user_id(justinbieber)
    for (String arg : keywords) {
        if (isNumericalArgument(arg)) {
            for (String id : arg.split(",")) {
                follow.add(Long.parseLong(id));
            }
        } else {
            track.addAll(Arrays.asList(arg.split(",")));
        }
    }
    long[] followArray = new long[follow.size()];
    for (int i = 0; i < follow.size(); i++) {
        followArray[i] = follow.get(i);
    }
    String[] trackArray = track.toArray(new String[track.size()]);

    // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
    //twitterStream.filter(new FilterQuery(0, followArray, trackArray));
    twitterStream.filter(new FilterQuery(followArray));
}