Example usage for twitter4j.conf ConfigurationBuilder setDebugEnabled

List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled

Introduction

In this page you can find the example usage for twitter4j.conf ConfigurationBuilder setDebugEnabled.

Prototype

public ConfigurationBuilder setDebugEnabled(boolean debugEnabled) 

Source Link

Usage

From source file:Twitter.Twitter.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("8e27WtNVhuIOt1EAyAdqV51Yk")
            .setOAuthConsumerSecret("dsgPVnwV53UwiPuAA5r0CbNykubjxmGHe7csf0Y1zGOV8KVe0r")
            .setOAuthAccessToken("4143520821-ZgULKYSyMRbrXytCvkmdGeXbd7L0bx4NOiM4fKC")
            .setOAuthAccessTokenSecret("jju1OwDCromI9r0QK1gU18MrFOkw1jsKFCQtXjFbv5G8A");

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

    twitter4j.Twitter tw = tf.getInstance();

    Status stat;/*from  w  w w  . jav  a 2 s.  co  m*/
    try {
        stat = tw.updateStatus(tweet.getText());

        //System.out.println("twitter updated");
    } catch (TwitterException ex) {
        Logger.getLogger(Twitter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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  w w . j  av  a2 s  .  c o m
    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 {/*  ww w.  j a v a  2  s  . c  om*/
        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:TwitterDownload.TwitterHandler.java

public TwitterHandler() {
    try {//from  w w  w  .j  av a 2 s . c  o  m
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET_KEY)
                .setOAuthAccessToken(null).setOAuthAccessTokenSecret(null);
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();
    } catch (IllegalStateException ex) {
        String s = ex.toString();
    } catch (Exception ex) {
        String s = ex.toString();
    }
}

From source file:twittermongodbapp.TwitterMongoDBApp.java

/**
 * @param args the command line arguments
 * @throws twitter4j.TwitterException//from   w  ww . ja  v a  2  s  .com
 */
public static void init(ConfigurationBuilder cf) {
    cf.setDebugEnabled(true);
    cf.setJSONStoreEnabled(true);
    cf.setOAuthConsumerKey("SkmxKecZHTxfKmGcQLh7tTufm");
    cf.setOAuthConsumerSecret("HPWFJ6jVrVvuCQd4qT1C0b9q3QqifU27mbcuW3M6f8f81IGGQn");
    cf.setOAuthAccessToken("719105233322905600-FTnAnBZBFZ4AADDTpNyJNPNidsVNvvv");
    cf.setOAuthAccessTokenSecret("D6yIzAKqBLrGLAdIsXk5XvdUehudkgUqO5S7xrWcYp5pu");
}

From source file:twitterplugin.TwitterSender.java

License:Open Source License

public void send(final Window parentWindow, final Program program, final TwitterSettings settings) {
    TwitterDialog dialog = new TwitterDialog(parentWindow, program, settings.getFormat());
    dialog.setLocationRelativeTo(parentWindow);
    dialog.setVisible(true);/*from   w w  w.  ja v  a  2  s .c om*/

    if (dialog.wasOkPressed()) {

        if (settings.getAccessToken() == null) {
            final TwitterLoginDialog login = new TwitterLoginDialog(parentWindow, settings);

            if (!(login.askLogin() == JOptionPane.OK_OPTION)) {
                return;
            }
        }

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(settings.getConsumerKey())
                .setOAuthConsumerSecret(settings.getConsumerSecret());
        TwitterFactory factory = new TwitterFactory(cb.build());
        AccessToken accessToken = settings.getAccessToken();
        Twitter twitter = factory.getInstance(accessToken);
        try {
            twitter.updateStatus(dialog.getMessage());
            DontShowAgainMessageBox.dontShowAgainMessageBox(TwitterPlugin.getInstance(), "tweetSent",
                    parentWindow, mLocalizer.msg("tweetSend", "The tweet was sent."));
        } catch (TwitterException e) {
            e.printStackTrace();
            ErrorHandler.handle(mLocalizer.msg("error", "Could not send tweet..."), e);
        }
    }
}

From source file:twittertestingagain.TwitterTesting.java

/**
 * @param args the command line arguments
 * @throws twitter4j.TwitterException/*w w  w  .  ja va 2 s .c  o  m*/
 * @throws java.io.IOException
 */
public static void main(String[] args) throws TwitterException, IOException {

    /* ---------------------------Setting up twitter account authentication-------------------------------*/
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("YjICBJeNlnxAf3tFw7awLaCzS")
            .setOAuthConsumerSecret("8IfPzkr4opePnhCLLloKMP6X44IeNav0fLDrmtBrPbaHoxd1nO")
            .setOAuthAccessToken("4146680697-oOEPVezvvZ82vB7iP9HSbkoTG9ze9gH69XLrSCP")
            .setOAuthAccessTokenSecret("HZjsaabmVjeSkSX6vvVFdT3GWZek8xJ9RKfwaR57RDyEG");

    /* ---------------------------------File Writing Variables------------------------------------------------*/

    File outfile = new File("output.txt");
    FileWriter fwriter = new FileWriter(outfile);

    try (PrintWriter pWriter = new PrintWriter(fwriter)) {

        /*----------------------------------Search Parameters-------------------------------------*/

        String search = "chinese food";
        String lang = "en";
        /*------------------------End Search Parameters----------------------------------------*/

        int numTweets = 0;
        long maxID = -1;
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        try {

            Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
            //System.out.println(rateLimitStatus);
            RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");

            /*System.out.printf("You have %d calls remaining out of %d, Limit resets in %d seconds\n",
                searchTweetsRateLimit.getRemaining(),
                searchTweetsRateLimit.getLimit(),
                searchTweetsRateLimit.getSecondsUntilReset());
            */

            for (int queryNumber = 0; queryNumber < maxQueries; queryNumber++) {

                System.out.printf("\n\n!!! Starting loop %d\n\n", queryNumber);
                pWriter.println("\n\n!!! Starting iteration #" + queryNumber + "\n\n");

                if (searchTweetsRateLimit.getRemaining() == 0) {
                    System.out.printf("!!! Sleeping for %d seconds due to rate limits\n",
                            searchTweetsRateLimit.getSecondsUntilReset());
                    Thread.sleep((searchTweetsRateLimit.getSecondsUntilReset() + 2) * 1000l);
                }
                //here is where we can send an object to the query
                Query query = new Query(search);
                query.setCount(tweetsPerQuery);
                query.resultType(Query.ResultType.recent);
                query.setLang(lang);

                if (maxID != -1) {
                    query.setMaxId(maxID - 1);
                }

                QueryResult result = twitter.search(query);

                if (result.getTweets().size() == 0) {
                    break;
                }

                for (Status s : result.getTweets()) {

                    numTweets++;

                    if (maxID == -1 || s.getId() < maxID) {
                        maxID = s.getId();
                    }

                    System.out.printf("On %s, @%-20s said: %s\n", s.getCreatedAt().toString(),
                            s.getUser().getScreenName(), cleanText(s.getText()));

                    pWriter.println("On " + s.getCreatedAt().toString() + " @" + s.getUser().getScreenName()
                            + " " + cleanText(s.getText()));

                }

                searchTweetsRateLimit = result.getRateLimitStatus();

            }

        }

        catch (Exception e) {

            System.out.println("Broken");

            e.printStackTrace();
        }
        System.out.printf("\n\nA total of %d tweets retrieved\n", numTweets);
        pWriter.println("\n\nA total of " + numTweets + " tweets retrieved\n\n");
        pWriter.close();

        /*while (result.hasNext()){
            numTweets += result.getCount();
        System.out.println(numTweets);
         for (Status status : result.getTweets()) {
             System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
         }  
         result.nextQuery();
        }
                   
                     
                 
                 
        /*
         QueryForm qf = new QueryForm();
           qf.show();
        */

    }

}

From source file:twittertimeline.MainFrame.java

public void SetTwitter() throws TwitterException {
    //Keys/*from   w w w  . j  a va  2 s. c o  m*/
    ConfigurationBuilder cf = new ConfigurationBuilder();
    cf.setDebugEnabled(true).setOAuthConsumerKey("").setOAuthConsumerSecret("").setOAuthAccessToken("")
            .setOAuthAccessTokenSecret("");

    //Create twitter object
    tw = new TwitterFactory(cf.build());
    twt = tw.getInstance();

    //Setting the photo of login user 
    BufferedImage img = null;
    try {
        img = ImageIO.read(new URL(twt.showUser("username").getOriginalProfileImageURL()));
        photo.setIcon(
                new ImageIcon(img.getScaledInstance(photo.getWidth(), photo.getHeight(), img.SCALE_DEFAULT)));

    } catch (Exception e) {
        photo.setText("Photo Error");
    }

    pg = new Paging(pageCounter);
    pageCounter++;

    //Get first page of timeline        
    status1 = twt.getHomeTimeline(pg);

    rtList = new ArrayList<Long>();
    fwList = new ArrayList<Long>();
    getTweets();
    showTweets();

}

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);/*from  w  w  w .  j ava2s.  c  om*/
            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:twitter_app_p1.Twitter_app_p1.java

public static void initialize_stuff() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("T9Gl1DWeRjeBazUInktTNtEtD")
            .setOAuthConsumerSecret("3NXrL1qGpF3WPVyJQ7ytInlhNjIsMgT6s7bJOIDhD1uotzZ958")
            .setOAuthAccessToken("2428771880-4e3LHhOzmiYx4lChlAEYtJ6sB2oetARYbXcqfyU")
            .setOAuthAccessTokenSecret("7HLOf3dafjJEGoioWOMHfgiNrhBDb66YJZgSzrDkTNA9x")
            .setJSONStoreEnabled(true);/*ww  w.j  ava 2s.  c  o m*/

    TwitterStreamFactory twitterStreamFact = new TwitterStreamFactory(cb.build());
    twitterStream = twitterStreamFact.getInstance();
}