List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
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);//from w w w.jav a 2s . co 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);/*w w w . j a v a 2 s .com*/ 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; }/*ww w . j a va2 s.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 .j a va2s.co 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();/*from w w w . ja 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:oauth.AppOAuth.java
License:Apache License
public TwitterFactory loadOAuthUser(String endpoint) throws ClassNotFoundException, SQLException, TwitterException { MysqlDB DB = new MysqlDB(); // System.out.println("DEBUG AppOAuth.java"); // get OAuth cradentials by calling DB's loadOAuthUser(endpoint) ConstVars StaticVars = DB.loadOAuthUser(endpoint); String consumer_key = StaticVars.consumer_key; String consumer_secret = StaticVars.consumer_secret; String user_token = StaticVars.user_token; String user_secret = StaticVars.user_secret; RemainingCalls = StaticVars.Remaining; screen_name = StaticVars.screen_name; // working with twitter4j.properties // Twitter twitter = new TwitterFactory().getInstance(); // initialize Twitter OAuth ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setJSONStoreEnabled(true).setDebugEnabled(true).setOAuthConsumerKey(consumer_key) .setOAuthConsumerSecret(consumer_secret).setOAuthAccessToken(user_token) .setOAuthAccessTokenSecret(user_secret); TwitterFactory tf = new TwitterFactory(cb.build()); return tf;/*from w ww.j av a2 s .c om*/ }
From source file:oauth.AppOAuth.java
License:Apache License
public TwitterFactory loadOAuthUser(String endpoint, int TOTAL_JOBS, int JOB_NO) throws ClassNotFoundException, SQLException, TwitterException { MysqlDB DB = new MysqlDB(); // System.out.println("DEBUG AppOAuth.java"); // get OAuth cradentials by calling DB's loadOAuthUser(endpoint) ConstVars StaticVars = DB.loadOAuthUser(endpoint, TOTAL_JOBS, JOB_NO); String consumer_key = StaticVars.consumer_key; String consumer_secret = StaticVars.consumer_secret; String user_token = StaticVars.user_token; String user_secret = StaticVars.user_secret; RemainingCalls = StaticVars.Remaining; screen_name = StaticVars.screen_name; // working with twitter4j.properties // Twitter twitter = new TwitterFactory().getInstance(); // initialize Twitter OAuth ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setJSONStoreEnabled(true).setDebugEnabled(true).setOAuthConsumerKey(consumer_key) .setOAuthConsumerSecret(consumer_secret).setOAuthAccessToken(user_token) .setOAuthAccessTokenSecret(user_secret); TwitterFactory tf = new TwitterFactory(cb.build()); return tf;//ww w .ja v a 2 s. c o m }
From source file:oauth.AppOAuth.java
License:Apache License
public TwitterFactory loadOAuthUser(String endpoint, String consumer_key, String consumer_secret, String user_token, String user_secret) throws ClassNotFoundException, SQLException, TwitterException { // Send OAuth credentials and get rate limit of endpoint String[] args = { endpoint, consumer_key, consumer_secret, user_token, user_secret }; StaticVars = GetRateLimitStatus.getRateLimit(args); RemainingCalls = StaticVars.Remaining; // working with twitter4j.properties // Twitter twitter = new TwitterFactory().getInstance(); // initialize Twitter OAuth ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setJSONStoreEnabled(true).setDebugEnabled(true).setOAuthConsumerKey(consumer_key) .setOAuthConsumerSecret(consumer_secret).setOAuthAccessToken(user_token) .setOAuthAccessTokenSecret(user_secret); TwitterFactory tf = new TwitterFactory(cb.build()); return tf;/*from www .ja v a2 s.co m*/ }
From source file:OAuth.MyOwnTwitterFactory.java
License:Open Source License
public Twitter createOneTwitterInstance() { Twitter twitter;/*from www. j a v a2s .c o m*/ ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(APIkeys.getTwitterAPIKey()); builder.setOAuthConsumerSecret(APIkeys.getTwitterAPISecret()); builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3"); builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j"); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance(); return twitter; }
From source file:OAuth.MyOwnTwitterFactory.java
License:Open Source License
public TwitterStream createOneTwitterStreamInstance(AccessToken accessToken) { TwitterStream twitterStream;/*w w w .ja v a2 s. c o m*/ ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(APIkeys.getTwitterAPIKey()); builder.setOAuthConsumerSecret(APIkeys.getTwitterAPISecret()); System.out.println("AT: " + accessToken.getToken()); System.out.println("ATS: " + accessToken.getTokenSecret()); builder.setOAuthAccessToken(accessToken.getToken()); builder.setOAuthAccessTokenSecret(accessToken.getTokenSecret()); builder.setJSONStoreEnabled(true); // builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3"); // builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j"); Configuration configuration = builder.build(); TwitterStreamFactory factory = new TwitterStreamFactory(configuration); twitterStream = factory.getInstance(); return twitterStream; }