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:PrintRetweetStream.java

License:Apache License

/**
 * Main entry of this application./* w  ww  . j a va  2s  .com*/
 *
 * @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 {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("");
    cb.setOAuthConsumerSecret("");
    cb.setOAuthAccessToken("");
    cb.setOAuthAccessTokenSecret("");

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).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.retweet();
}

From source file:Read_data.java

/**
 * @param args the command line arguments
 * @throws twitter4j.TwitterException/*  w  w  w. ja v a  2  s .  c o  m*/
 * @throws java.io.FileNotFoundException
 */
public static void main(String[] args) throws TwitterException, FileNotFoundException, IOException {
    // TODO code application logic here

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(customer_key).setOAuthConsumerSecret(customer_secret)
            .setOAuthAccessToken(access_token).setOAuthAccessTokenSecret(access_token_secret);

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

    StatusListener statusListener = new StatusListener() {

        @Override
        public void onStatus(Status status) {

            //get the place if it is not null
            if (status.getPlace() != null) {

                try {

                    String place = status.getPlace().getName();

                    System.out.println("Place: " + place + "\t\t\t" + "Tweet: " + status.getText());

                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Read_data.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        @Override

        public void onDeletionNotice(StatusDeletionNotice sdn) {
            System.out.print("");
        }

        @Override
        public void onTrackLimitationNotice(int i) {
            System.out.print("");
        }

        @Override
        public void onScrubGeo(long l, long l1) {
            System.out.print("");
        }

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

        @Override
        public void onException(Exception ex) {
            System.out.println(ex);
        }
    };

    FilterQuery fq = new FilterQuery();

    //Stream tweets with these keywords. Replace for your tweets that you are looking for.
    String keywords[] = { "lol", "lls", "lmao", "llf" };

    fq.track(keywords);

    twitterStream.addListener(statusListener);
    twitterStream.filter(fq);

    try {
        synchronized (lock) {
            lock.wait();
        }
    } catch (InterruptedException e) {
        System.out.println(e);
    }
    System.out.println("returning statuses");
    // twitterStream.shutdown();
}

From source file:GetHomePageData.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w  w  w .  j  av a2 s .c o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try {
        /* TODO output your page here. You may use following sample code. */
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet GetHomePageData</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet GetHomePageData at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("Olwk4ncLNgYZcROLvP9oAFrgv")
                .setOAuthConsumerSecret("eht2OHYflAV1Cu8GP9XA46zm7KbiivY35TytvJ91aMX67brKEF")
                .setOAuthAccessToken("1668200646-cR34ReTvqAUgQGNvFQWlbGNkGgksXvq7yFHWlO6")
                .setOAuthAccessTokenSecret("VAU21C4JHFCrbBfwDfTkdLEkSkpjBD7VFkFowFwLPAuoC");

        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        List<Status> statuses;
        //statuses= twitter.getHomeTimeline();
        out.println("Showing home timeline.");
        // for (Status status : statuses) 
        //   out.println(status.getUser().getName() + ":" +     status.getText());

    } catch (Exception e) {

    }
}

From source file:PrintRawSampleStream.java

License:Apache License

/**
 * Main entry of this application.// w  w  w  .  j  a v  a 2s. 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 {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("");
    cb.setOAuthConsumerSecret("");
    cb.setOAuthAccessToken("");
    cb.setOAuthAccessTokenSecret("");

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

    RawStreamListener listener = new RawStreamListener() {
        @Override
        public void onMessage(String rawJSON) {
            System.out.println(rawJSON);
        }

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

From source file:PrintLinksStream.java

License:Apache License

/**
 * Main entry of this application.//from www. java 2 s.  com
 *
 * @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 {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("");
    cb.setOAuthConsumerSecret("");
    cb.setOAuthAccessToken("");
    cb.setOAuthAccessTokenSecret("");

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).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.links(0);
}

From source file:PrintSampleStream.java

License:Apache License

/**
 * Main entry of this application./*from  www  . j  av  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 {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("");
    cb.setOAuthConsumerSecret("");
    cb.setOAuthAccessToken("");
    cb.setOAuthAccessTokenSecret("");

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

From source file:twitterGateway_v2_06.java

License:Creative Commons License

public void SetupTwitter() {
    //twitterIn = new TwitterConnectStream();
    //accessToken = new AccessToken(TwitterAccessToken, TwitterAccessTokenSecret);
    //TwitterOAuthAuthorization.setOAuthAccessToken(accessToken);
    //TwitterOAuthAuthorization = new OAuthAuthorization(conf);
    //TwitterOAuthAuthorization.setOAuthConsumer(TwitterConsumerKey, TwitterConsumerSecret);
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(TwitterConsumerKey)
            .setOAuthConsumerSecret(TwitterConsumerSecret).setOAuthAccessToken(TwitterAccessToken)
            .setOAuthAccessTokenSecret(TwitterAccessTokenSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitterOut = tf.getInstance();/*  ww w . j a  v  a2s  . c om*/
    //  try {
    //  twitterOut.updateStatus("Hello World!");
    //  }
    //  catch (TwitterException ex) {
    //    println(ex);
    //  }
    ActivityLogAddLine("twitter connector ready");
    output = createWriter("log.txt");

    StatusListener twitterIn = new StatusListener() {
        public void onStatus(Status status) {
            double Longitude;
            double Latitude;
            GeoLocation GeoLoc = status.getGeoLocation();
            if (GeoLoc != null) {
                //println("YES got a location");
                Longitude = GeoLoc.getLongitude();
                Latitude = GeoLoc.getLatitude();
            } else {
                Longitude = 0;
                Latitude = 0;
            }
            println(TimeStamp() + "\t" + Latitude + "\t" + Longitude + "\t" + status.getUser().getScreenName()
                    + "\t" + status.getText());
            output.println(TimeStamp() + "\t" + Latitude + "\t" + Longitude + "\t"
                    + status.getUser().getScreenName() + "\t" + status.getText());
            output.flush();
            TwitterToOsc(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) {
            println("CAUGHT in the ACT: " + ex);
        }
    };

    ConfigurationBuilder cbIn = new ConfigurationBuilder();
    cbIn.setDebugEnabled(true).setOAuthConsumerKey(TwitterConsumerKey)
            .setOAuthConsumerSecret(TwitterConsumerSecret).setOAuthAccessToken(TwitterAccessToken)
            .setOAuthAccessTokenSecret(TwitterAccessTokenSecret);

    TwitterStreamFactory ts = new TwitterStreamFactory(cbIn.build());
    TwitterStream twitterStream = ts.getInstance();
    twitterStream.addListener(twitterIn);

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

From source file:PrintFilterStream.java

License:Apache License

/**
 * Main entry of this application.// w  w w  .ja  v  a2s.  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);
    }

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

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("");
    cb.setOAuthConsumerSecret("");
    cb.setOAuthAccessToken("");
    cb.setOAuthAccessTokenSecret("");

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).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(",")));
        }
    }
    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:PrintSiteStreams.java

License:Apache License

/**
 * Main entry of this application./*from  www  .j a  v a 2 s.c  o 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.PrintSiteStreams [follow(comma separated numerical user ids)]");
        System.exit(-1);
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("");
    cb.setOAuthConsumerSecret("");
    cb.setOAuthAccessToken("");
    cb.setOAuthAccessTokenSecret("");

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

    String[] split = args[0].split(",");
    long[] followArray = new long[split.length];
    for (int i = 0; i < followArray.length; i++) {
        followArray[i] = Long.parseLong(split[i]);
    }

    // site() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
    twitterStream.site(true, followArray);
}

From source file:Register.java

License:Open Source License

/**
 * Usage: java twitter4j.examples.tweets.UpdateStatus [text]
 *
 * @param args message/*from  www .  j av a2  s  . co m*/
 */
public static void main(String[] args) {
    try {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("wIb1qVNc0CNXQJxduYIXw")
                .setOAuthConsumerSecret("vTES3U9862wYaxFRdMyD1LRatkq2R42mDyOjXLHIdk");

        Twitter twitter = new TwitterFactory(cb.build()).getInstance();
        AccessToken accessToken = null;
        try {
            // get request token.
            // this will throw IllegalStateException if access token is already available
            RequestToken requestToken = twitter.getOAuthRequestToken();

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while (null == accessToken) {
                System.out.println("Open the following URL and grant access to your account:");
                System.out.println(requestToken.getAuthorizationURL());
                System.out.print("Enter the PIN(if available) and hit enter after you granted access. [PIN]:");
                String pin = br.readLine();
                try {
                    if (pin.length() > 0) {
                        accessToken = twitter.getOAuthAccessToken(requestToken, pin);
                    } else {
                        accessToken = twitter.getOAuthAccessToken(requestToken);
                    }
                } catch (TwitterException te) {
                    if (401 == te.getStatusCode()) {
                        System.out.println("Unable to get the access token.");
                    } else {
                        te.printStackTrace();
                    }
                }
            }
            System.out.println("Access granted to Twitter.");
            System.out.println("Access token: " + accessToken.getToken());
            System.out.println("Access token secret: " + accessToken.getTokenSecret());
        } catch (IllegalStateException ie) {
            // access token is already available, or consumer key/secret is not set.
            if (!twitter.getAuthorization().isEnabled()) {
                System.out.println("OAuth consumer key/secret is not set.");
                System.exit(-1);
            }
        }
        twitter.updateStatus("Minecraft server successfully registered at " + (new Date()).toString());
        System.out.println("Successfully connected to Twitter.");

        // Write the properties file
        PrintWriter pw = new PrintWriter(new FileWriter("../TwitterEvents.properties"));
        pw.println("accessToken=" + accessToken.getToken());
        pw.println("accessTokenSecret=" + accessToken.getTokenSecret());
        pw.close();

        System.out.println("Your TwitterEvents.properties file has been created with your access tokens.");
        System.out.println("Start Minecraft server to load the remaining default values.");
        System.out.println("Then reload TwitterEvents if you make any changes.");
        System.exit(0);
    } catch (TwitterException te) {
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.out
                .println("Try revoking access to the hModEvents application from your Twitter settings page.");
        System.exit(-1);
    } catch (IOException ioe) {
        System.out.println("Failed to read the system input.");
        System.exit(-1);
    }
}