List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled
public ConfigurationBuilder setDebugEnabled(boolean debugEnabled)
From source file:nl.isaac.dotcms.twitter.util.TwitterUtil.java
License:Creative Commons License
public TwitterUtil(String twitterConsumerKey, String twitterSecretConsumerKey, String twitterAccessToken, String twitterSecretAccessToken) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true) //Added for extra logging .setOAuthConsumerKey(twitterConsumerKey).setOAuthConsumerSecret(twitterSecretConsumerKey) .setOAuthAccessToken(twitterAccessToken).setOAuthAccessTokenSecret(twitterSecretAccessToken) .setUseSSL(true);// www.j a v a 2s. c o m TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); }
From source file:nl.utwente.bigdata.bolts.TimelineBolt.java
License:Apache License
@Override public void prepare(Map stormConf, TopologyContext context) { String consumerKey = (String) stormConf.get("consumerKey"); String consumerSecret = (String) stormConf.get("consumerSecret"); String accessToken = (String) stormConf.get("accessToken"); String accessTokenSecret = (String) stormConf.get("accessTokenSecret"); System.out.printf("%s %s %s %s\n", consumerKey, consumerSecret, accessToken, accessTokenSecret); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret) .setJSONStoreEnabled(true);/* ww w. j a v a2 s .c o m*/ TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); try { getRateLimit(); } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:noki.preciousshot.helper.TwitterHelper.java
License:Apache License
public static void tweetMedia(String text, File file) { Thread thread = new Thread() { private String text; private File file; public Thread setArgs(String text, File file) { this.text = text; this.file = file; return this; }//from www . j av a2s. c o m @Override public void run() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(PreciousShotData.twitterKeys[0]) .setOAuthConsumerSecret(PreciousShotData.twitterKeys[1]) .setOAuthAccessToken(PreciousShotData.twitterKeys[2]) .setOAuthAccessTokenSecret(PreciousShotData.twitterKeys[3]); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { Status status = twitter.updateStatus(new StatusUpdate(this.text).media(this.file)); if (status != null && status.getId() != 0) { String url = String.format("https://twitter.com/%s/status/%s", twitter.getScreenName(), status.getId()); PreciousShotCore.log("the url is %s.", url); LangHelper.sendChatWithUrl(LangKey.TWITTER_SUCCESS, LangKey.TWITTER_URL, url); } else { LangHelper.sendChat(LangKey.TWITTER_FAILED); } } catch (TwitterException e) { LangHelper.sendChat(LangKey.TWITTER_FAILED); } } }.setArgs(text, file); thread.start(); }
From source file:nselive.NSELive.java
/** * @param args the command line arguments */// w w w . jav a 2 s .c o m public static void main(String[] args) { try { String url = "http://www.nellydata.com/CapitalFM/livedata.asp"; //fetch data String docString = Jsoup.connect(url).get().toString(); String[] tBodyArray = docString.split("<tbody>"); String[] tableArray = tBodyArray[1].split("</tbody>"); String tableContent = tableArray[0].trim(); //delete header rows String[] headerlessContent = tableContent.split("Low</strong> </td>"); String[] rowArray = headerlessContent[1].split("<tr>"); //skip rowArray[0] which has string "</tr> for (int i = 1; i <= rowArray.length - 1; i++) { String rowContent = rowArray[i]; String[] cellArray = rowContent.split("</td>"); Stock stock = new Stock(); String[] idArray = cellArray[0].split("mycell\">"); stock.setId(Integer.parseInt(idArray[1])); String[] stockNameArray1 = cellArray[1].split("<strong>"); String[] stockNameArray2 = stockNameArray1[1].split("</strong>"); stock.setName(stockNameArray2[0]); String[] priceYesterdayArray = cellArray[2].split("mycell\">"); stock.setPriceYesterday(Double.parseDouble(priceYesterdayArray[1].replace(",", ""))); String[] currentPriceArray = cellArray[3].split("style2\">"); stock.setCurrentPrice(Double.parseDouble(currentPriceArray[1].replace(",", ""))); if (stock.getCurrentPrice() != stock.getPriceYesterday()) { String tweet = ""; //TODO: Change to hourly updates if (stock.getCurrentPrice() > stock.getPriceYesterday()) { tweet = stock.getName().toUpperCase() + " has RISEN to " + stock.getCurrentPrice() + " from " + stock.getPriceYesterday() + " yesterday"; } else if (stock.getCurrentPrice() < stock.getPriceYesterday()) { tweet = stock.getName().toUpperCase() + " has FALLEN to " + stock.getCurrentPrice() + " from " + stock.getPriceYesterday() + " yesterday"; } //get the following from your twitter account String consumerKey = "yourConsumerKey"; String consumerSecret = "yourConsumerSecret"; String accessToken = "yourAccessToken"; String accessSecret = "yourAccessSecret"; ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessSecret); try { TwitterFactory factory = new TwitterFactory(cb.build()); Twitter twitter = factory.getInstance(); Status status = twitter.updateStatus(tweet); System.out.println("NEW TWEET: " + status.getText()); } catch (TwitterException te) { te.printStackTrace(); System.exit(-1); } } } } catch (IOException ex) { System.out.println("Ooops! No data this time. Our connection timed out :("); Logger.getLogger(NSELive.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:nyu.twitter.lg.FentchTwitter.java
License:Open Source License
public static void invoke() throws Exception { init();// w ww . j a v a 2 s. co m // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else { // Create a table with a primary hash key named 'name', which holds // a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("id") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.waitForTableToBecomeActive(dynamoDB, tableName); } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Emwo2pG").setOAuthConsumerSecret("RM9B7fske5T") .setOAuthAccessToken("19ubQOirq").setOAuthAccessTokenSecret("Lbg3C"); final TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { if (status.getGeoLocation() != null && status.getPlace() != null) { // if (count == 0) { // count++; // } // latitude = status.getGeoLocation().getLatitude(); longtitude = status.getGeoLocation().getLongitude(); place = status.getPlace().getCountry() + "," + status.getPlace().getFullName(); date = status.getCreatedAt().toString(); id = Integer.toString(count); name = status.getUser().getScreenName(); message = status.getText(); System.out.println("---------------------------"); System.out.println("ID:" + count); System.out.println("latitude:" + latitude); System.out.println("longtitude:" + longtitude); System.out.println("place:" + place); System.out.println("name:" + name); System.out.println("message:" + message); System.out.println("data:" + date); System.out.println("-------------8-------------"); insertDB(id, count, name, longtitude, latitude, place, message, date); if (++count > 100) { twitterStream.shutdown(); System.out.println("Information Collection Completed"); } // count = (count+1) % 101; } } @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:ontoSentiment.Amigos.java
@Override public void run() { ConfigurationBuilder cb = new ConfigurationBuilder(); //the following is set without accesstoken- desktop client cb.setDebugEnabled(true).setOAuthConsumerKey("FBd5n7dyl8mCz73qyfZ0p4XHb") .setOAuthConsumerSecret("vu5Xt5TzBSL9naOZylIYlx5MdcRlhH2LvkpW6KIkxSf9AqwuGt") .setOAuthAccessToken("3232400175-lAchtC6ChWMTnJKe3BaWbst8SucIaTjn5gm4Rp2") .setOAuthAccessTokenSecret("DnkquBWAS6igYpM8Z4r54hH7ztcfMX6u8OzMXBLwM9Xkh"); try {/* ww w . java 2 s. c om*/ TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); //User u = twitter.showUser("karlaffabiola"); User u = twitter.showUser("raythemaster"); IDs ids; System.out.println("Listing followers's ids."); System.out.println("ID: " + u.getId()); System.out.println("Nome: " + u.getScreenName()); long cursor = -1; PagableResponseList<User> pagableFollowings; List<User> listFriends = new ArrayList<>(); List<User> listFriends2 = new ArrayList<>(); pagableFollowings = twitter.getFriendsList(u.getId(), cursor, 200); System.out.println("Qunatidade followers: " + pagableFollowings.size()); for (User user : pagableFollowings) { System.out.println("Id: " + user.getId() + " Nome: " + user.getScreenName()); listFriends.add(user); // ArrayList<User> } for (User user : listFriends) { System.out.println("Id1: " + user.getId() + " Nome1: " + user.getScreenName()); pagableFollowings = twitter.getFriendsList(user.getId(), cursor, 200); System.out.println("Qunatidade followers: " + pagableFollowings.size()); for (User user2 : pagableFollowings) { System.out.println("Id2: " + user2.getId() + " Nome2: " + user2.getScreenName()); listFriends2.add(user2); // ArrayList<User> } } System.out.println("Lista 1:" + listFriends.size()); System.out.println("Lista 2:" + listFriends2.size()); System.exit(0); } catch (TwitterException te) { // te.printStackTrace(); System.out.println("Failed to get timeline: " + new Date()); try { Thread.sleep(3 * 60 * 1000); run(); } catch (InterruptedException ex) { Logger.getLogger(Amigos.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.apache.apex.malhar.contrib.twitter.TwitterSampleInput.java
License:Apache License
/** * Allow derived classes to customize the configuration */// www . j a va2 s . co m protected ConfigurationBuilder setupConfigurationBuilder() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(debug).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); return cb; }
From source file:org.apache.nutch.protocol.http.api.HttpBase.java
License:Apache License
private TwitterFactory getTwitterFactoryWithConfigParams(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret) .setPrettyDebugEnabled(true); TwitterFactory tf = new TwitterFactory(cb.build()); return tf;//from w w w .j a va 2s .com }
From source file:org.apache.s4.example.twitter.TwitterInputAdapter.java
License:Apache License
public void connectAndRead() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties twitterProperties = new Properties(); File twitter4jPropsFile = new File(System.getProperty("user.home") + "/twitter4j.properties"); if (!twitter4jPropsFile.exists()) { logger.error(//from w w w . java 2 s. c om "Cannot find twitter4j.properties file in this location :[{}]. Make sure it is available at this place and includes user/password credentials", twitter4jPropsFile.getAbsolutePath()); return; } twitterProperties.load(new FileInputStream(twitter4jPropsFile)); cb.setDebugEnabled(Boolean.valueOf(twitterProperties.getProperty("debug"))) .setUser(twitterProperties.getProperty("user")) .setPassword(twitterProperties.getProperty("password")); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onException(Exception ex) { logger.error("error", ex); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { logger.error("error"); } @Override public void onStatus(Status status) { messageQueue.add(status); } @Override public void onScrubGeo(long userId, long upToStatusId) { logger.error("error"); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { logger.error("error"); } }; twitterStream.addListener(statusListener); twitterStream.sample(); }
From source file:org.apparatus_templi.service.TwitterService.java
License:Open Source License
private void start() { accessToken = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccess); accessTokenKey = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccessKey); if (accessToken != null && accessTokenKey != null) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenKey); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();/* w ww .j a va 2s .c o m*/ } else { Log.e(TAG, "Twitter service requires authentication for a particular user account."); } }