List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled
public ConfigurationBuilder setDebugEnabled(boolean debugEnabled)
From source file:com.mycompany.dovetune.SignIn.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w.j av a 2 s . c om*/ * * @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 { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Djgh7AmnNzxmv7fXzqlsdj8RB") .setOAuthConsumerSecret("Mnj40YllwKBBZvOkndnrmxl1TaNvcnS0x40PFhhDnMHysgzHum"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); request.getSession().setAttribute("twitter", twitter); try { StringBuffer callbackURL = request.getRequestURL(); System.out.println("TwitterLoginServlet:callbackURL:" + callbackURL); int index = callbackURL.lastIndexOf("/"); callbackURL.replace(index, callbackURL.length(), "").append("/Callback"); RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString()); request.getSession().setAttribute("requestToken", requestToken); System.out.println("requestToken.getAuthenticationURL():" + requestToken.getAuthenticationURL()); response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { throw new ServletException(e); } }
From source file:com.mycompany.omnomtweets.Search.java
public static void main(String[] args) throws TwitterException { System.setProperty("twitter4j.loggerFactory", "twitter4j.internal.logging.NullLoggerFactory"); if (args.length >= 1) { candidate = Candidate.valueOf(args[0]); System.out.println("Getting tweets on " + candidate.name); } else {/*ww w .j av a 2 s . c o m*/ //System.out.println("You didn't give me a candidate, so you get TRUMP"); } //System.out.println("Starting at: " + sdf.format(new Date())); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(candidate.consumerKey) .setOAuthConsumerSecret(candidate.consumerSecret).setOAuthAccessToken(candidate.accessToken) .setOAuthAccessTokenSecret(candidate.accessTokenSecret); final ArrayList<Status> statuses = new ArrayList<>(); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { public void onStatus(Status status) { statuses.add(status); writeToStdErr(status); //Removed because writing to STD OUT instead. //System.out.println("statuses: " + statuses.size()); if (statuses.size() >= 100) { /*System.out.println("Writing " + statuses.size() + " to file " + "at: " + sdf.format(new Date()));*/ writeTweetsToFile(statuses, candidate.name + "StreamTweets.txt"); statuses.clear(); } } 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) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; FilterQuery fq = new FilterQuery(); String keywords[] = candidate.aliases; fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); }
From source file:com.mycompany.twitterapp.TwitterApp.java
public void buildConfig() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("").setOAuthConsumerSecret("").setOAuthAccessToken("") .setOAuthAccessTokenSecret(""); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();// w w w . jav a 2 s . c o m }
From source file:com.mycompany.twitterproductanalysistool.TwitterAPI.java
public TwitterAPI() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("ogluOfaFe00xjVQ5WfynhkWQY") .setOAuthConsumerSecret("l4yL7iz6J1zEBaY4ownHu9VnIu2zSLuELVyzxykgoSEF3vzSup") .setOAuthAccessToken("1101064884-uMgjzYHHo82fRZdwWbvjNWs8ZKqoZj0xsKB4jnO") .setOAuthAccessTokenSecret("WyCAT00L4FK0lOQiXhshNXpS5bHVFoVsaoYGlJYVylWYm"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();//from w w w. ja v a2 s. co m }
From source file:com.mycompany.twittersearch.SignIn.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . j a v a2s . 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 { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("").setOAuthConsumerSecret(""); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); request.getSession().setAttribute("twitter", twitter); try { StringBuffer callbackURL = request.getRequestURL(); System.out.println("TwitterLoginServlet:callbackURL:" + callbackURL); int index = callbackURL.lastIndexOf("/"); callbackURL.replace(index, callbackURL.length(), "").append("/Callback"); RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString()); request.getSession().setAttribute("requestToken", requestToken); System.out.println("requestToken.getAuthenticationURL():" + requestToken.getAuthenticationURL()); response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { throw new ServletException(e); } }
From source file:com.narvis.frontend.twitter.AccessTwitter.java
License:Open Source License
private Pair<TwitterStream, Twitter> loadAccessTwitter(String token, String tokenSecret, String consumerKey, String consumerSecret) {//from w ww . ja v a 2 s . com ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(token); cb.setOAuthAccessTokenSecret(tokenSecret); Configuration authConf = cb.build(); return new Pair(new TwitterStreamFactory(authConf).getInstance(), new TwitterFactory(authConf).getInstance()); }
From source file:com.oldterns.vilebot.handlers.user.UrlTweetAnnouncer.java
License:Open Source License
/** * Accesses the source of a HTML page and looks for a title element * /* w w w .j a va2s . c o m*/ * @param url http tweet String * @return String of text which represents the tweet. Empty if error. */ private String scrapeURLHTMLTitle(String url) { String text = ""; URL page; try { page = new URL(url); } catch (MalformedURLException x) { // System.err.format("scrapeURLHTMLTitle new URL error: %s%n", x); return text; } //split the url into pieces, change the request based on what we have String parts[] = url.split("/"); int userPosition = 0; long tweetID = 0; for (int i = 0; i < parts.length; i++) { if (parts[i].toString().equals("twitter.com")) userPosition = i + 1; if (parts[i].toString().equals("status") || parts[i].toString().equals("statuses")) tweetID = Long.valueOf(parts[i + 1].toString()).longValue(); } if (userPosition == 0) return text; else { try { String consumerKey = ""; //may be known as 'API key' String consumerSecret = ""; //may be known as 'API secret' String accessToken = ""; //may be known as 'Access token' String accessTokenSecret = ""; //may be known as 'Access token secret' ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); if (tweetID != 0) //tweet of the twitter.com/USERID/status/TWEETID variety { Status status = twitter.showStatus(tweetID); return (status.getUser().getName() + ": " + status.getText()); } else //just the user is given, ie, twitter.com/USERID { User user = twitter.showUser(parts[userPosition].toString()); if (!user.getDescription().isEmpty()) //the user has a description return ("Name: " + user.getName() + " | " + user.getDescription() + "\'\nLast Tweet: \'" + user.getStatus().getText()); else //the user doesn't have a description, don't print it return ("Name: " + user.getName() + "\'\nLast Tweet: \'" + user.getStatus().getText()); } } catch (TwitterException x) { return text; } } }
From source file:com.ontotext.s4.TwitterVisualization.downloadTweets.SearchTweets.java
License:Open Source License
/** * Creates and configures Twitter client instance with provided credentials. * /*from w w w. ja va2 s.c om*/ * @return Twitter instance */ private Twitter ConfigurateTwitterAccount() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret) .setJSONStoreEnabled(true); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); return twitter; }
From source file:com.redhat.middleware.jdg.TwitterDemoClient.java
License:Open Source License
public void startAsync() { ConfigurationBuilder cb = new ConfigurationBuilder(); if (accessTokenSecret == null || accessToken == null) { try {/*w w w. j a va 2s . co m*/ this.authorize(); } catch (Exception e) { logger.log(Level.SEVERE, "error occured while authorizing", e); } } cb.setDebugEnabled(false).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); twitterStream.addListener(new DemoTwitterListener(twitterStream)); twitterStream.sample(); }
From source file:com.richardstansbury.tweetfollow.TwitterHelper.java
License:Open Source License
/** * Creates an authentication configuration for accessing the _twitter streaming * API.//from ww w .j a v a 2s .c o m * * See readme.txt in root folder for location and format of twitter4j.txt. * * @param c - context to access the asset's folder * @return configuration object based upon keys read from asset's folder */ private Configuration readConfiguration(Context c) { //Create a Configuration Builder ConfigurationBuilder cb = new ConfigurationBuilder(); try { //Create an input stream for the properties file BufferedReader in = new BufferedReader(new InputStreamReader(c.getAssets().open("twitter4j.txt"))); //Set up the configuration cb.setDebugEnabled(true).setOAuthConsumerKey(in.readLine()).setOAuthConsumerSecret(in.readLine()) .setOAuthAccessToken(in.readLine()).setOAuthAccessTokenSecret(in.readLine()); } catch (IOException io) { Log.e("TwitterHelper", "Error opening input file"); System.exit(-1); } //Build the configuration and return the object return cb.build(); }