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:twitter.stream.PrintFilterStream.java

License:Apache License

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

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

    final ConnectionManager c = new ConnectionManager();
    try {
        c.createConnection();
        c.createDB();
        c.closeConnection();

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        System.out.println(e);
    }
    System.out.println("conexion creada");

    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {

            //            pw.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            //            if (status.getGeoLocation() != null)
            //               pw.println("Lat:" + status.getGeoLocation().getLatitude() + "Long"
            //                     + status.getGeoLocation().getLongitude());

            //            User u = status.getUser();
            //            try {
            //               System.out.println("User: id: " + u.getId() + " name: " + u.getName());
            //               c.insertTwitterUser(u);
            //            } catch (SQLException e1) {
            //               // TODO Auto-generated catch block
            //               System.out.println(e1);
            //            }
            //            
            //            if (status.isRetweet()) {
            //               
            //               System.out.println("RT Found!, getting the original tweet");
            //               Status retweetedStat = status.getRetweetedStatus();
            //               u = retweetedStat.getUser();
            //               System.out.println("RT User: id: " + u.getId() + " name: " + u.getName());
            //
            //               try {
            //            
            //                     c.insertTwitterUser(u);
            //                     
            //                     c.insertTweet(retweetedStat);
            //                     
            //                  
            //                  
            //                  
            //               } catch (SQLException e) {
            //                  // TODO Auto-generated catch block
            //                  System.out.println(e);
            //               }
            //               
            //            }
            //            if(status.getQuotedStatus() != null){
            //               
            //               System.out.println("Quoted Found!, getting the original tweet");
            //               Status quotedStatus = status.getQuotedStatus();
            //               u = quotedStatus.getUser();
            //               System.out.println("Quoted User: id: " + u.getId() + " name: " + u.getName());
            //
            //               try {
            //                  c.insertTwitterUser(u);
            //                  c.insertTweet(quotedStatus);
            //               } catch (SQLException e) {
            //                  // TODO Auto-generated catch block
            //                  System.out.println(e);
            //               }
            //            }
            //            
            //      
            //            
            //            try {
            //               c.insertTweet(status);
            //            } catch (SQLException e) {
            //               // TODO Auto-generated catch block
            //               System.out.println(e);
            //            }

            try {
                c.recursiveInsert(status, 0);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                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 twitterStream = new TwitterStreamFactory().getInstance();

    FilterQuery fq = new FilterQuery();

    String keywords[] = { "election2016", "NeverTrump", "Hillary2016", "Trump", "HillarysEmail",
            "2016election" };

    fq.track(keywords);

    twitterStream.addListener(listener);
    twitterStream.filter(fq);
}

From source file:twitter4j.examples.stream.PrintFilterStream.java

License:Apache License

/**
 * Main entry of this application.//from   w  ww.  j a  v a 2 s  .co m
 *
 * @param args follow(comma separated user ids) track(comma separated filter terms)
 * @throws TwitterException when Twitter service or network is unavailable
 */
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);
    }

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(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();
        }
    });

    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(",")));
        }
    }
    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:twitter4j.examples.stream.PrintFirehoseStream.java

License:Apache License

/**
 * Main entry of this application./*from   ww  w .  jav  a 2  s  .  c  o m*/
 *
 * @param args arguments doesn't take effect with this example
 * @throws TwitterException when Twitter service or network is unavailable
 */
public static void main(String[] args) throws TwitterException {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(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();
        }
    }).firehose(0);
}

From source file:twitter4j.examples.stream.PrintLinksStream.java

License:Apache License

/**
 * Main entry of this application.//from  ww  w .  ja va2  s  . co  m
 *
 * @param args arguments doesn't take effect with this example
 * @throws TwitterException when Twitter service or network is unavailable
 */
public static void main(String[] args) throws TwitterException {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(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();
        }
    }).links(0);
}

From source file:twitter4j.examples.stream.PrintRetweetStream.java

License:Apache License

/**
 * Main entry of this application.//from   w w w  . j  a va 2s  .c om
 *
 * @param args arguments doesn't take effect with this example
 * @throws TwitterException when Twitter service or network is unavailable
 */
public static void main(String[] args) throws TwitterException {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(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();
        }
    }).retweet();
}

From source file:twitter4j.examples.stream.PrintSampleStream.java

License:Apache License

/**
 * Main entry of this application.//w  w  w.ja v  a  2s .co m
 *
 * @param args arguments doesn't take effect with this example
 * @throws TwitterException when Twitter service or network is unavailable
 */
public static void main(String[] args) throws TwitterException {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(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();
        }
    }).sample();
}

From source file:twitterapp.TwitterApp.java

public static void streamTweets() throws TwitterException {
    /*getting the trends */
    ConfigurationBuilder cb2 = new ConfigurationBuilder();

    cb2.setDebugEnabled(true).setOAuthConsumerKey("S01GsVwuCAwZFp5BLg5C4k8PT")
            .setOAuthConsumerSecret("6jo0jo4b05Ec5ZJcf74v5yGUQu5v8DryUwypOBjPD6jaItRNzd")
            .setOAuthAccessToken("794259549297446912-Z3AWruBmLa7QmCO6BnybCSj1tZXNqbB")
            .setOAuthAccessTokenSecret("6ezMQPQVziW9yxyTITZA8Wc2RJWjcBKvbXZU4dOjo4bge");

    TwitterFactory tf = new TwitterFactory(cb2.build());
    Twitter twitter = tf.getInstance();/* w  ww . j av a  2 s.  c  om*/
    Trends trends = twitter.getPlaceTrends(23424977);

    String top_trend = "";
    int top = 0;
    for (Trend trend : trends.getTrends()) {
        if (top < 1) {
            top_trend = trend.getName();
            top++;
        }
    }

    System.out.println("top trend : " + top_trend);

    //Using the Streaming API to get real time tweets based on the trending topics as keywords
    /* configurating twiter4j */

    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setDebugEnabled(true).setOAuthConsumerKey("S01GsVwuCAwZFp5BLg5C4k8PT")
            .setOAuthConsumerSecret("6jo0jo4b05Ec5ZJcf74v5yGUQu5v8DryUwypOBjPD6jaItRNzd")
            .setOAuthAccessToken("794259549297446912-Z3AWruBmLa7QmCO6BnybCSj1tZXNqbB")
            .setOAuthAccessTokenSecret("6ezMQPQVziW9yxyTITZA8Wc2RJWjcBKvbXZU4dOjo4bge")
            .setJSONStoreEnabled(true);
    /* end of configuration */

    MongoClient mongo = new MongoClient("localhost", 27017);
    MongoDatabase database = mongo.getDatabase("myTweetdb2");
    MongoCollection<Document> collection = database.getCollection("myTweetCol5");
    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    StatusListener listener;
    listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {

            String rawJSON = TwitterObjectFactory.getRawJSON(status);
            Document doc = Document.parse(rawJSON);

            collection.insertOne(doc);

        }

        @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.sample();
    twitterStream.addListener(listener);
    FilterQuery fq = new FilterQuery();

    String keywords[] = { top_trend };
    fq.track(keywords);
    twitterStream.filter(fq);
}

From source file:TwitterCrawler.PrintSampleStream.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");

    //final PrintSampleStream pr = new PrintSampleStream();

    try {/*from w  ww .  j a v  a2  s . c  o m*/
        pr.LinkMongodb();
    } catch (Exception e) {
        e.printStackTrace();
    }

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

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    StatusListener listener = new StatusListener() {

        @Override
        public void onException(Exception ex) {
            // TODO Auto-generated method stub
            ex.printStackTrace();
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            // TODO Auto-generated method stub
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());

        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            // TODO Auto-generated method stub
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @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);
                pr.collection.insert(dbObject);
                System.out.println(dbObject);
                pr.count++;
                /* if(pr.count>300000) {  
                pr.mongo.close();  
                System.exit(0);  
                 }  */
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            // TODO Auto-generated method stub
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);

        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };
    twitterStream.addListener(listener);

    //String[] Track = {"why Obama look like he about to drop the best album of 2013?"}; 
    String[] trackArray = { "Mac", "App", "Store" };
    //trackArray[1] = ;  

    // Create a FilterQuery object and then set the items to track
    FilterQuery filter = new FilterQuery();

    // Create an array of items to track
    //String[] itemsToTrack = {""}; 
    // Set the items to track using FilterQuerys' track method.
    //filter.track(Track); 
    filter.track(trackArray);

    // Assuming you have already created Twitter/TwitterStream object, 
    // use the filter method to start streaming using the FilterQuery object just created.
    twitterStream.filter(filter);

    /* String[] username = {"katyperry"};
     twitterStream.addListener(userlistener);  
     twitterStream.user();*/
    //pr.mongo.close();
}

From source file:twittertweetscollection.TwitterTweetsCollection.java

public List<Status> execute() throws TwitterException {

    final List<Status> statuses = new ArrayList();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("I7WYWBE6eSNKdV4FYSyiuP0uk")
            .setOAuthConsumerSecret("oft7Y6WcUCvxovPU5modCZ3BOlHH2z9Px73UkFMILN4ltBhOni")
            .setOAuthAccessToken("3524247253-o7zXFn3r8PwPb4IUTYqHRQzVabTzfoFn9Ck7FzW")
            .setOAuthAccessTokenSecret("V7zkLiJmF0vsdX8rUdkXo3q1ha452vKqVtB5OoCuQWAgR");

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    StatusListener listener = new StatusListener() {

        public void onStatus(Status status) {
            statuses.add(status);/*w w w. j  av  a  2s.  com*/
            System.out.println(statuses.size() + ":" + status.getText());
            if (statuses.size() > 100) {
                synchronized (lock) {
                    lock.notify();
                }
                System.out.println("unlocked");
            }
        }

        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();
        }

        @Override
        public void onStallWarning(StallWarning sw) {
            System.out.println(sw.getMessage());

        }
    };

    //FilterQuery fq = new FilterQuery();
    //String keywords[] = { "SuperBowlSunday"};

    //fq.track(keywords);

    twitterStream.addListener(listener);
    twitterStream.sample();
    //twitterStream.filter(fq);

    try {
        synchronized (lock) {
            lock.wait();
        }
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("returning statuses");
    twitterStream.shutdown();
    return statuses;
}

From source file:uk.ac.susx.tag.method51.twitter.FileStatusListener.java

License:Apache License

@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
    long uid = statusDeletionNotice.getUserId();
    long sid = statusDeletionNotice.getStatusId();
    //LOG.info("Deletion notice recieved uid: " + uid + " sid: " + sid );

    try {/*from ww w .j a v a2s  .  co  m*/
        Writer w = new FileWriter(outputDir + File.separator + deletionNoticeFileName, true);
        w.write(Long.toString(uid));
        w.write("\t");
        w.write(Long.toString(sid));
        w.write("\n");
        w.close();
    } catch (IOException e) {
        LOG.error("", e);
    }

}