List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
From source file:com.wimbli.serverevents.Register.java
License:Open Source License
private static void execute() { try {//from ww w . j a v a2s . c om ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("QyuUqx8UFaRLMWORQinphg") .setOAuthConsumerSecret("EWORHYNo3JkJgvihiGwFL8tWNHExyhWFilR1Q"); twitter = new TwitterFactory(cb.build()).getInstance(); accessToken = null; try { // get request token. // this will throw IllegalStateException if access token is already available requestToken = twitter.getOAuthRequestToken(); msg("Open the following URL and grant access to ServerEvents:"); msg(requestToken.getAuthorizationURL()); outputToFile("Open the following URL and grant access to ServerEvents: \n" + requestToken.getAuthorizationURL()); msg("For convenience, this URL has also been output to a file: " + outFile); if (cmdLine) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.print( "Enter the PIN(if available) and hit enter after you have granted access. [PIN]:"); String pin = br.readLine(); tryPin(pin); } } } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is not set. if (!twitter.getAuthorization().isEnabled()) { msg("OAuth consumer key/secret is not set."); exit(-1); } } } catch (TwitterException te) { msg("Failed to get timeline: " + te.getMessage()); msg("Try revoking access to the ServerEvents application from your Twitter settings page."); exit(-1); } catch (IOException ioe) { msg("Failed to read the system input."); exit(-1); } if (cmdLine) exit(0); }
From source file:com.wso2.stream.connector.protocol.TwitterPollingConsumer.java
License:Open Source License
/** * Setting up a connection with Twitter Stream API with the given credentials */// www .j a va2 s .co m private void setupConnection() { StatusListener listener = new StatusListenerImpl(); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken) .setOAuthAccessTokenSecret(accessSecret); TwitterStream twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); twitterStream.addListener(listener); FilterQuery query = new FilterQuery(); query.language(new String[] { "en" }); query.track(filterTags); twitterStream.filter(query); }
From source file:com.yattatech.dbtc.util.TwitterUtil.java
License:Open Source License
public static Twitter getTwitter() { if (sTwitter == null) { final ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setHttpConnectionTimeout(Constants.TWITTER_TIMEOUT); sTwitter = new TwitterFactory(builder.build()).getInstance(); // These values represents DBTC Twitter app credentials, don't // expose that data to anyone else final String twitterKey = DBTCApplication.sApplicationContext.getString(R.string.twitter_key); final String twitterSecret = DBTCApplication.sApplicationContext.getString(R.string.twitter_secret); sTwitter.setOAuthConsumer(twitterKey, twitterSecret); }//from w w w . j av a2 s . c o m return sTwitter; }
From source file:com.yfiton.notifiers.twitter.TwitterNotifier.java
License:Apache License
public TwitterNotifier() throws NotificationException { super(CLIENT_ID, SECRET_ID, PromptReceiver.class, TwitterWebEngineListener.class); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setGZIPEnabled(true).setDebugEnabled(true).setOAuthConsumerKey(getClientId()) .setOAuthConsumerSecret(getClientSecret()); com.yfiton.notifiers.twitter.AccessToken accessToken = getAccessToken(); if (accessToken != null) { configurationBuilder.setOAuthAccessToken(accessToken.getAccessToken()); configurationBuilder.setOAuthAccessTokenSecret(accessToken.getAccessTokenSecret()); }//from www. java 2s . co m twitter = new TwitterFactory(configurationBuilder.build()).getInstance(); }
From source file:com.zeus3110.iotstation.DeviceServer.java
License:Apache License
private void TwitterSetting() { cb = new ConfigurationBuilder(); // change your key and token cb.setDebugEnabled(true).setOAuthConsumerKey(TwitterKey.CONSUMER_KEY) .setOAuthConsumerSecret(TwitterKey.CONSUMER_SECRET).setOAuthAccessToken(TwitterKey.ACCESS_TOKEN_KEY) .setOAuthAccessTokenSecret(TwitterKey.ACCESS_TOKEN_SECRET); factory = new TwitterFactory(cb.build()); Log.i(TAG, "Twetter Auth Setting End"); }
From source file:Control.MyOwnTwitterFactory.java
License:Open Source License
public Twitter createOneTwitterInstance() { Twitter twitter;// w ww.j av a 2 s . co m ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(APIkeys.getTwitterAPIKey()); builder.setOAuthConsumerSecret(APIkeys.getTwitterAPISecret()); builder.setUseSSL(true); Configuration configuration = builder.build(); twitter4j.TwitterFactory factory = new twitter4j.TwitterFactory(configuration); twitter = factory.getInstance(); return twitter; }
From source file:Controller.DetailsmesoffresController.java
@FXML void partageTwitter(ActionEvent event) throws TwitterException, FileNotFoundException { OffreService offreService = new OffreService(); FXMLAfficheroffresController z = new FXMLAfficheroffresController(); Offre x = offreService.findById(Integer.parseInt(FXMLAfficheroffresController.getLabelid())); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("zFrvXiT4O6bPh7wtfX2qpxTJM") .setOAuthConsumerSecret("pZeG2yJ71HYSu3y8MC4sbOcAeKstRKmp8bVKfCOmxnd4QjsKmC") .setOAuthAccessToken("3345656831-F533Ns9kdMPI6GfmHwiVor3BUHM6kYJn4WO4xhq") .setOAuthAccessTokenSecret("1hWrntZlel0gOju0xOEVf2t5kRo2CjSp5H75sieOUfT89"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); String pathphoto = x.getPhoto(); String nomphoto = pathphoto.substring(62); System.out.println(nomphoto); File file = null;/*from w w w . j a va 2 s . co m*/ file = new File(x.getPhoto()); String StatusMessage = (x.getPtvente().getNom() + "\n" + x.getDescription() + "\n" + x.getTaux_remise()); StatusUpdate status = new StatusUpdate(StatusMessage); status.setMedia(file); tw.updateStatus(status); }
From source file:Controller.DetailsOffreController.java
@FXML void partagersurtwitter(ActionEvent event) throws TwitterException { OffreService offreService = new OffreService(); AfficherToutesOffresController z = new AfficherToutesOffresController(); Offre x = offreService.findById(Integer.parseInt(AfficherToutesOffresController.getLabelid())); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("zFrvXiT4O6bPh7wtfX2qpxTJM") .setOAuthConsumerSecret("pZeG2yJ71HYSu3y8MC4sbOcAeKstRKmp8bVKfCOmxnd4QjsKmC") .setOAuthAccessToken("3345656831-F533Ns9kdMPI6GfmHwiVor3BUHM6kYJn4WO4xhq") .setOAuthAccessTokenSecret("1hWrntZlel0gOju0xOEVf2t5kRo2CjSp5H75sieOUfT89"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); String pathphoto = x.getPhoto(); String nomphoto = pathphoto.substring(62); System.out.println(nomphoto); File file = null;/*from w ww .ja va 2 s. c o m*/ file = new File(x.getPhoto()); String StatusMessage = (x.getPtvente().getNom() + "\n" + x.getDescription() + "\n" + x.getTaux_remise()); StatusUpdate status = new StatusUpdate(StatusMessage); status.setMedia(file); tw.updateStatus(status); }
From source file:CR.CERA.SensoryMotor.Twitter.Authorization.java
public Authorization() throws IOException, TwitterException { /* ww w . j a va 2s . co m*/ ConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.setDebugEnabled(true) .setOAuthConsumerKey("String con el Consumer key de la aplicacin (Ver en la web de Twitter Developer)") .setOAuthConsumerSecret("String con el Consumer secret de la aplicacin (Ver en la web de Twitter Developer)"); Twitter OAuthTwitter = new TwitterFactory(configBuilder.build()).getInstance(); RequestToken requestToken = null; AccessToken accessToken = null; String url = null; }
From source file:crawler.TwitterFeed.java
/** * *//*from ww w . ja va 2 s. c o m*/ public void get_tweets() throws SQLException { CSVReader cr = new CSVReader(); ArrayList<String> names = new ArrayList<>(); Map<String, String> name_ticker; names = cr.get_company_names(tickers); System.out.println(names); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey("WNSycI2GS33ZAwHJ9Fb4A"); cb.setOAuthConsumerSecret("BBWeSThT3ZV2g9c5BDuUduDyNAWyzouMI0XjQy7KUc"); cb.setOAuthAccessToken("1852271029-SLfE061bImfcRxWQZpy1pAgpEkfFhg3757Q9JRf"); cb.setOAuthAccessTokenSecret("1uPSfYPbaENtXFYWsryBIAHnUsmG3pT6lGH0NzxTCGW7O"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); for (String s : names) { String[] temp; if (s.contains(",")) { temp = s.split(","); } else { temp = s.split(" "); } System.out.println( "--------------------------------------------------------------------------------------" + temp[0]); Query query = new Query("#" + temp[0]); query.lang("en"); int numberOfTweets = 500; long lastID = Long.MAX_VALUE; ArrayList<Status> tweets = new ArrayList<>(); while (tweets.size() < numberOfTweets) { if (numberOfTweets - tweets.size() > 100) { query.setCount(100); } else { query.setCount(numberOfTweets - tweets.size()); } try { QueryResult result = twitter.search(query); tweets.addAll(result.getTweets()); System.out.println("Gathered " + tweets.size() + " tweets"); for (Status t : tweets) { if (t.getId() < lastID) { lastID = t.getId(); } } } catch (TwitterException te) { System.out.println("Couldn't connect: " + te); } query.setMaxId(lastID - 1); } Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/CrawledData", "root", ""); for (int i = 0; i < tweets.size(); i++) { Status t = (Status) tweets.get(i); //GeoLocation loc = t.getGeoLocation(); String user = t.getUser().getScreenName(); String msg = t.getText(); String time = t.getCreatedAt().toString(); //if (loc!=null) { // Double lat = t.getGeoLocation().getLatitude(); // Double lon = t.getGeoLocation().getLongitude(); // System.out.println(i + " USER: " + user + " wrote: " + msg + " located at " + lat + ", " + lon); //} //else{ System.out.println(i + " USER: " + user + " wrote: " + msg + " at: " + time); //} try { Class.forName("com.mysql.jdbc.Driver"); PreparedStatement ps = con .prepareStatement("INSERT IGNORE INTO TwitterFeed VALUES (?,?,?,?,?)"); ps.setString(1, s); ps.setString(2, cr.get_ticker_from_company(s)); ps.setString(3, user); ps.setString(4, msg); ps.setString(5, time); int k = ps.executeUpdate(); if (k <= 0) { System.out.println("Entry Unsuccessful"); } else { System.out.println("Entry Successful"); } } catch (ClassNotFoundException | SQLException e) { System.out.println(e); } } con.close(); } }