Example usage for twitter4j StatusDeletionNotice getUserId

List of usage examples for twitter4j StatusDeletionNotice getUserId

Introduction

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

Prototype

long getUserId();

Source Link

Usage

From source file:cloudcomputebot.MentionListener.java

License:Open Source License

@Override
public void onDeletionNotice(StatusDeletionNotice sdn) {
    System.out.println(sdn.getUserId() + "'s status deleted!");
}

From source file:com.freshdigitable.udonroad.util.TwitterResponseMock.java

License:Apache License

@NonNull
public static StatusDeletionNotice createDeletionNotice(final Status target) {
    final StatusDeletionNotice mock = mock(StatusDeletionNotice.class);
    final long statusId = target.getId();
    when(mock.getStatusId()).thenReturn(statusId);
    final long userId = target.getUser().getId();
    when(mock.getUserId()).thenReturn(userId);
    return mock;/*from www  .j  av  a2s.c  o m*/
}

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

License:Apache License

public static void convert(StatusDeletionNotice statusDeletionNotice, Struct struct) {
    struct.put("StatusId", statusDeletionNotice.getStatusId());
    struct.put("UserId", statusDeletionNotice.getUserId());
}

From source file:com.narvis.frontend.twitter.input.Input.java

License:Open Source License

@Override
public void onDeletionNotice(StatusDeletionNotice sdn) {
    NarvisLogger.logInfo("User " + sdn.getUserId() + " deleted tweet : " + sdn.getStatusId());
}

From source file:crosstreams.twitter.TwitterStreamFileWriter.java

License:Mozilla Public License

/**
 * Start crawling tweets/*  www  .  j a v  a  2 s .  co m*/
 * @param args
 * @throws TwitterException
 */
public static void main(String[] args) throws TwitterException {

    System.err.println("### Twitter Stream Writer ###");
    System.err.println("Saves tweets from the Spritzer/Gardenhose Stream to a series of files");
    System.err.println(
            "Command: crosstreams.twitter.TwitterStreamFileWriter <saveFolder> <twitterusername> <twitterpassword> <numberoftweetstostoreperfile>(optional)");
    System.err.println("   saveFolder: Where the tweets will be downloaded to");
    System.err.println("   twitterusername: The username of the twitter account to use for downloading tweets");
    System.err.println("   twitterpassword: The password of the twitter account to use for downloading tweets");
    System.err.println(
            "   numberoftweetstostoreperfile: The total number of tweets to write to a file before closing that file and opening a new one (Integer) (defaults=1000000)");
    System.err.println("Optional System Properties (-D):");
    System.err.println("   http.proxyhost: The proxy host to use if needed");
    System.err.println("   http.proxyport: The proxy port to use if needed");
    System.err.println("   email: An email address to send alerts to if an error is encountered");
    System.err.println("   emailconf: An file containing the javax.mail configuration");
    System.err.println(
            "   emailonvalidate: true/false - should I send an email when a file is correctly validated rather than only when it fails? (default=false)");

    if (args.length <= 1 || args.length >= 5) {
        System.err.println("Example:");
        System.err.println(
                "java -Demail=\"MYEMAIL@HOST.COM\" -Demailconf=\"./javamail.conf\" -Demailonvalidate=\"true\" -jar TwitterStreamFileCrawler.jar ./ MYUSERNAME MYPASSWORD 100000");
        System.err.println("Don't forget to modify ./javamail.conf to contain your email server host");
        System.exit(0);
    }

    // user inputs
    String saveFolder = args[0];
    String username = args[1];
    String password = args[2];
    final int numberOfTweetsToStorePerFile;
    if (args.length > 2)
        numberOfTweetsToStorePerFile = Integer.parseInt(args[3]);
    else
        numberOfTweetsToStorePerFile = 1000000;
    String proxyhost = System.getProperty("http.proxyhost");
    String proxyport = System.getProperty("http.proxyport");
    final String email = System.getProperty("email");
    final String emailconf = System.getProperty("emailconf");

    // define the user account in use and proxy settings if needed
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    if (proxyhost != null && proxyport != null) {
        cb.setHttpProxyHost(proxyhost);
        cb.setHttpProxyPort(Integer.parseInt(proxyport));
    }
    cb.setUser(username);
    cb.setPassword(password);

    if (!saveFolder.endsWith("/") && !saveFolder.endsWith("\\")) {
        saveFolder = saveFolder + System.getProperty("file.separator");
    }
    final String finalSaveFolder = saveFolder;

    // Twitter4J Stream - the type of stream is set automatically, i.e. Gardenhose if you have it, Spritzer otherwise.
    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    // The status listener is the important bit, this fires when a new tweet arrives.
    StatusListener listener = new StatusListener() {

        /** The status listener holds a writer to save content to **/
        BufferedWriter statusWriter = null; // the tweets go here
        BufferedWriter logWriter = null; // we write any delete requests or error messages here

        /** We store a fixed number of Tweets in each file **/
        int numberInThisFile = numberOfTweetsToStorePerFile;
        int numberPerFile = numberOfTweetsToStorePerFile;

        String currentFilename;
        int numerrors = 0;

        /**
         * A new tweet has arrived
         */
        public void onStatus(Status status) {
            if (numberInThisFile >= numberPerFile) {
                // closing and opening of new files
                try {
                    if (statusWriter != null) {

                        statusWriter.close();
                        logWriter.close();
                        validateJSONFile(currentFilename, numberPerFile);
                    }
                    Long currentTime = System.currentTimeMillis();

                    currentFilename = finalSaveFolder + currentTime.toString() + ".json.gz";
                    statusWriter = new BufferedWriter(new OutputStreamWriter(
                            new GZIPOutputStream(new FileOutputStream(currentFilename)), "UTF-8"));
                    logWriter = new BufferedWriter(new OutputStreamWriter(
                            new GZIPOutputStream(
                                    new FileOutputStream(finalSaveFolder + currentTime.toString() + ".log.gz")),
                            "UTF-8"));
                    numberInThisFile = 0;
                    numerrors = 0;
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            numberInThisFile++;
            // write the JSON - note that I added the getJSON() method to the Twitter4J status object
            // this is why the Twitter4j sources are included rather than importing the jar.
            try {
                Object s = status.getJSON();
                statusWriter.write(status.getJSON().toString() + '\n');
                statusWriter.flush();
            } catch (Exception e) {
                e.printStackTrace();
                numerrors++;
                if (emailconf != null && email != null && numerrors < 5)
                    Mail.mail(emailconf, email, email, "Twitter Stream Writer Alert - Write Failed",
                            "An IOException was thrown when calling statusWriter.write()." + '\n'
                                    + e.getMessage() + '\n'
                                    + "The current file will be closed and a new file will be created.");
            }
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            try {
                logWriter.write("DEL: " + statusDeletionNotice.getStatusId() + " "
                        + statusDeletionNotice.getUserId() + '\n');
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            try {
                logWriter.write("LIMIT: " + numberOfLimitedStatuses + '\n');
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void onScrubGeo(long userId, long upToStatusId) {
            try {
                logWriter.write("SCRUBGEO: " + userId + " " + upToStatusId + '\n');
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void onException(Exception ex) {
            if (logWriter == null)
                return;
            try {
                logWriter.write("ERR: " + ex.getLocalizedMessage() + '\n');
                logWriter.flush();
                if (statusWriter != null) {
                    statusWriter.close();
                    statusWriter = null;
                    logWriter.close();
                    validateJSONFile(currentFilename, numberPerFile);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            //ex.printStackTrace();
        }
    };
    if (emailconf != null && email != null)
        Mail.mail(emailconf, email, email, "Twitter Stream Writer Info - Writer has started",
                "The Gardenhose Writer has begun crawling the stream (this email indicates that you will recieve alerts if something goes wrong.");
    twitterStream.addListener(listener);
    twitterStream.sample();
}

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:streamflow.spout.twitter.TwitterSampleSpout.java

License:Apache License

@Override
public void open(Map config, TopologyContext context, SpoutOutputCollector collector) {
    this.collector = collector;

    logger.info(//from ww w . j a v a2  s.  c  o m
            "Twitter Sampler Started: Consumer Key = " + consumerKey + ", Consumer Secret = " + consumerSecret
                    + ", Access Token = " + accessToken + ", Access Token Secret = " + accessTokenSecret);

    if (StringUtils.isNotBlank(consumerKey) && StringUtils.isNotBlank(consumerSecret)
            && StringUtils.isNotBlank(accessToken) && StringUtils.isNotBlank(accessTokenSecret)) {
        // Build the twitter config to authenticate the requests
        ConfigurationBuilder twitterConfig = new ConfigurationBuilder().setOAuthConsumerKey(consumerKey)
                .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken)
                .setOAuthAccessTokenSecret(accessTokenSecret).setJSONStoreEnabled(true)
                .setIncludeEntitiesEnabled(true).setIncludeEntitiesEnabled(true);

        // Add the proxy settings to the Twitter config if they were specified
        if (StringUtils.isNotBlank(proxyHost) && proxyPort > 0) {
            try {
                twitterConfig.setHttpProxyPort(proxyPort).setHttpProxyHost(proxyHost);
            } catch (Exception ex) {
            }
        }

        // Status listener which handle the status events and add them to the queue
        StatusListener listener = new StatusListener() {
            @Override
            public void onStatus(Status status) {
                queue.offer(status);
            }

            @Override
            public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
                logger.debug("Twitter Deletion Notice: " + statusDeletionNotice.getUserId());
            }

            @Override
            public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
                logger.debug("Twitter On Track Limitation Notice: Number Of Limited Statuses"
                        + numberOfLimitedStatuses);
            }

            @Override
            public void onScrubGeo(long userId, long upToStatusId) {
                logger.debug("Twitter Scrub Geo: UserID = " + userId + ", UpToStatusId = " + upToStatusId);
            }

            @Override
            public void onException(Exception exception) {
                logger.debug("Twitter Exception: " + exception.getMessage());
            }

            @Override
            public void onStallWarning(StallWarning stallWarning) {
                logger.debug("Twitter Stall Warning: " + stallWarning.toString());
            }
        };

        TwitterStreamFactory twitterFactory = new TwitterStreamFactory(twitterConfig.build());
        twitterStream = twitterFactory.getInstance();
        twitterStream.addListener(listener);
        twitterStream.sample();

        logger.info("Twitter Sample Stream Initialized");

    } else {
        logger.info("Twitter Sampler missing required OAuth properties. "
                + "Pleast check your settings and try again.");
    }
}

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 w w  w.  ja v  a 2s .c o 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);
    }

}

From source file:uk.co.flax.ukmp.twitter.UKMPStatusStreamHandler.java

License:Apache License

@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
    LOGGER.debug("{} : handling status deletion for user {}, status ID {}", name,
            statusDeletionNotice.getUserId(), statusDeletionNotice.getStatusId());
    searchEngine.deleteStatus(statusDeletionNotice.getUserId(), statusDeletionNotice.getStatusId());
}