List of usage examples for twitter4j TwitterFactory getSingleton
public static Twitter getSingleton()
From source file:rtb.RandomTweetBot.java
License:Apache License
public RandomTweetBot(final boolean reply) { twitter = TwitterFactory.getSingleton(); tweets = new ArrayList<>(); random = new Random(System.currentTimeMillis()); previousTweet = null;// ww w .j a v a2 s .c o m allowsReply = reply; logger = LoggerFactory.getLogger(RandomTweetBot.class); }
From source file:srss.core.TweetPlugin.java
License:MIT License
public void authReqest() { try {/*from w w w .j a va 2 s .com*/ this.twitter = TwitterFactory.getSingleton(); this.reqest = twitter.getOAuthRequestToken(); Desktop.getDesktop().browse(new URI(this.reqest.getAuthorizationURL())); } catch (TwitterException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:teambootje.TwitterAPI.java
public static void timeline() throws TwitterException, SQLException { Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query("ssrotterdam"); query.setCount(100);/* w w w. j a v a2 s . co m*/ /** ** setSince kan alleen tot 7 dagen terug worden gebruikt*** */ QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { if (status.getPlace() != null) { cityVar = status.getPlace().getName(); countryVar = status.getPlace().getCountry(); } else { countryVar = null; cityVar = null; } java.util.Date utilDate = status.getCreatedAt(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); date = sqlDate; post = status.getText(); screenName = status.getUser().getScreenName(); try { ImportIntoSQL.TwitterImport(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:twitter.botframework.connector.TwitterBotframeworkConnector.java
/** * @param args the command line arguments *//* w w w.j a v a 2 s. co m*/ public static void main(String[] args) throws TwitterException, ApiException, InterruptedException { // TODO code application logic here //access the twitter API using your twitter4j.properties file Twitter twitter = TwitterFactory.getSingleton(); GetDirectMessage(twitter); //print a message so we know when it finishes System.out.println("Done."); }
From source file:twitter.Cliente.java
private void btnEnviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnviarActionPerformed Twitter twitter = TwitterFactory.getSingleton(); String mensaje = txtMensaje.getText(); try {//w w w . j av a 2 s .c o m Status status = twitter.updateStatus(mensaje); } catch (TwitterException ex) { Logger.getLogger(Cliente.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:twitter4j.examples.lambda.RateLimitLambda.java
License:Apache License
public static void main(String... args) { Twitter twitter = TwitterFactory.getSingleton(); twitter.onRateLimitStatus(/* w w w .ja v a2s .c o m*/ e -> System.out.println("rate limit remaining: " + e.getRateLimitStatus().getRemaining())); for (int i = 0; i < 20; i++) { try { System.out.println(twitter.getHomeTimeline()); } catch (TwitterException e) { e.printStackTrace(); } } }
From source file:twitterapi.TwitterAPI.java
public static void timeline() throws TwitterException, SQLException { Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query("ssrotterdam"); query.setCount(100);//from w w w . j a v a 2 s. c o m /** ** setSince kan alleen tot 7 dagen terug worden gebruikt*** */ QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { String locationCity = null; String locationCountry = null; if (status.getPlace() != null) { cityVar = status.getPlace().getName(); countryVar = status.getPlace().getCountry(); } else { countryVar = null; cityVar = null; } java.util.Date utilDate = status.getCreatedAt(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); date = sqlDate; post = status.getText(); screenName = status.getUser().getScreenName(); try { ImportIntoSQL.TwitterImport(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:twitterbot.TwitterActions.java
public TwitterActions() { this.lastStatusTime = this.lastRetweetFromFile(); this.tweetAlreadyused = new ArrayList<Status>(); if (this.twitter != null) { } else {// w w w .j a v a 2 s . c o m this.twitter = TwitterFactory.getSingleton(); } }
From source file:twitterclient.TwitterClient.java
/** * @param args the command line arguments */// w ww . ja v a 2s .co m public static void main(String[] args) throws TwitterException { // The factory instance is re-useable and thread safe. Twitter twitter = TwitterFactory.getSingleton(); Status status = twitter.updateStatus("452045245204523.4532"); System.out.println("Successfully updated the status to [" + status.getText() + "]."); }
From source file:twitteremoji.FXMLDocumentController.java
public void setup(Stage stage) { this.stage = stage; try {/*from ww w . j ava 2 s . co m*/ // start twitter auth process twitter = TwitterFactory.getSingleton(); twitter.setOAuthConsumer(key, secret); RequestToken requestToken = twitter.getOAuthRequestToken(); // check if we have a token for the user, if not authenticate and store in prefs if (!TokenPref.hasToken()) { System.out.println("has no prefs!"); Dialogs dialog = Dialogs.create().owner(null).title("Grant account access") .masthead("You must grant TwitterEmoji access to your account") .message( "You only have to do this once. Go to Twitter authorisation webpage (opens default browser)?") .actions(Dialog.Actions.NO, Dialog.Actions.YES); Action response = dialog.showConfirm(); if (response.textProperty().getValue().contains("No")) { Platform.exit(); return; } try { java.awt.Desktop.getDesktop().browse(new URI(requestToken.getAuthorizationURL())); } catch (IOException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); Platform.exit(); return; } catch (URISyntaxException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); Platform.exit(); return; } // get pin Optional<String> responsePin = Dialogs.create().owner(stage).title("Authentication") .masthead("Authorise TwitterEmoji to get pin").message("Please enter pin:").showTextInput(); // One way to get the response value. String pin = null; if (responsePin.isPresent()) { pin = responsePin.get(); } AccessToken accessToken = null; if (pin == null) { accessToken = twitter.getOAuthAccessToken(); } else { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } // assume got, otherwise TwitterException thrown // store tokens TokenPref.putToken(accessToken.getToken()); TokenPref.putSecret(accessToken.getTokenSecret()); } else { System.out.println("has prefs!"); /* Dialogs dialog = Dialogs.create() .owner(null) .title("Information") .masthead("Application has Twitter token/secret") .message("Token: "+TokenPref.getToken()+"\nSecret: "+TokenPref.getSecret()); dialog.showInformation(); */ //Status status = twitter.updateStatus("testing api"); AccessToken accessToken = new AccessToken(TokenPref.getToken(), TokenPref.getSecret()); twitter.setOAuthAccessToken(accessToken); Dialogs dialog = Dialogs.create().owner(null).title("Information") .masthead("Twitter authentication").message("Connected to Twitter"); dialog.showInformation(); } } catch (TwitterException ex) { Dialogs.create().owner(null).title("Error").masthead(null) .message("Twitter authentication could not be completed").showError(); Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); Platform.exit(); return; } statusLabel.setText(STATUS_PREFIX + STATUS_CONNECTED); /* // add close behaviour to window to shut down twitter stage.setOnHiding(new EventHandler<WindowEvent>() { public void handle(WindowEvent event) { // TODO : check if this is triggered just by window minimisation // stop system System.out.println("--- Twitter client stopped"); } }); */ /* // add message reader (new Thread() { public void run() { // do what? } }).start(); */ }