List of usage examples for twitter4j StatusUpdate StatusUpdate
public StatusUpdate(String status)
From source file:ens.demo.twitter.PostServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//www . j a v a 2 s .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 { request.setCharacterEncoding("UTF-8"); String text = request.getParameter("text"); Twitter twitter = (Twitter) request.getSession().getAttribute("twitter"); try { StatusUpdate update = new StatusUpdate(text); twitter.updateStatus(update); } catch (TwitterException e) { throw new ServletException(e); } response.sendRedirect(request.getContextPath() + "/"); }
From source file:ens.demo.twitter.TwittEmergencyMessage.java
@Override public void run() { try {//from ww w . java 2 s . c o m if (toCustomer.getToken() == null || toCustomer.getToken().isEmpty()) { return; } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Properties properties = new Properties(); properties.load(classLoader.getResourceAsStream("twitter4j.properties")); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(properties.getProperty("twitter4j.oauth.consumerKey")) .setOAuthConsumerSecret(properties.getProperty("twitter4j.oauth.consumerSecret")) .setOAuthAccessToken(toCustomer.getToken()) .setOAuthAccessTokenSecret(toCustomer.getTokenSecret()); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); StatusUpdate update = new StatusUpdate(message); Status status = twitter.updateStatus(update); System.out.println("Successfully updated the status to [" + status.getText() + "]."); } catch (TwitterException ex) { Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:erando.controllers.AddProductController.java
@FXML private void addProductAction(ActionEvent event) throws FileNotFoundException, IOException, TwitterException, DocumentException { Product p = new Product(); Sms sms = new Sms(); ISms smsservice = new SmsService(); IShopService productService = new ProductService(); Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("YYYY:MM/HH:mm:ss"); p.setTitre(pTitre.getText());/* ww w . j a va 2s . c o m*/ p.setPrix(Integer.parseInt(pPrix.getText())); p.setDescription(pDescription.getText()); p.setType(pType.getValue().toString()); p.setDate(sdf.format(cal.getTime())); p.setImage(imageName); if (!pTitre.getText().isEmpty() && !pPrix.getText().isEmpty() && !pDescription.getText().isEmpty() && !pType.getValue().toString().isEmpty()) { productService.add(p); ////////send sms to subs sms.setNum("" + Parameters.user.getNumTel()); sms.setMessagetel("Product Added To Store go check it !"); smsservice.sendSms(sms); ////////share on facebook (when asked by the owner ! ) if (shareFacebook.isSelected()) { String accessToken = "EAACEdEose0cBAKLtkZBKZCBoEkx4MApf3HxDMAR93PoJ6lAAuZAMdfY9vtob2ii78C6TN88hSV8HK0tDZBskaUz5pcbH1HqVeDRISuEHsG0qqUZBca4gHGnANPWcZBSZA9RNFHpbwVHJ46ITntn52SGQWetPPaZBsNlsFXbpcDrKytOVtmspQzfrM8GiUQtm1kQZD"; FacebookClient fbClient = new DefaultFacebookClient(accessToken, Version.LATEST); File fs = new File("C:\\Users\\F.Mouhamed\\Desktop\\Esprit\\ERandoPi\\userfiles\\"); fs.getParentFile().setExecutable(true); fs.getParentFile().setReadable(true); fs.getParentFile().setWritable(true); ////////FileInputStream fis = new FileInputStream(fs.getParentFile()); User me = fbClient.fetchObject("me", User.class); FacebookType response; response = fbClient.publish("me/feed", FacebookType.class, Parameter.with("message", p.getTitre() + "\n " + p.getDescription() + "\n Prix:" + p.getPrix())); } ////////share on twitter (when asked by the owner ! ) if (shareTwitter.isSelected()) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("dHU6c4cXI6HDeLI3pakG8PYtp") .setOAuthConsumerSecret("n0NxZVXgpEMGJboWYBSD1nfbaa3Ov2qL0e9h2GzyUsa8wQ0q0p") .setOAuthAccessToken("729655065716346881-gukmKiOsT5WFv05t3yfQFrWgoPycQGD") .setOAuthAccessTokenSecret("4qTGW5YdG8j9biJeAybzIcivCPZaAOqES2PhoJI9S7WKL"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); String StatusMessage = ("Titre :" + p.getTitre() + "\nDescription:\n" + p.getDescription() + "\nPrix:" + p.getPrix()); StatusUpdate status = new StatusUpdate(StatusMessage); tw.updateStatus(status); } /////////show notification Notifications notificationBuilder = Notifications.create().title("sucess").text("produit ajouter") .graphic(null).hideAfter(Duration.seconds(4)).position(Pos.BOTTOM_RIGHT); notificationBuilder.darkStyle(); notificationBuilder.showConfirm(); /////////send emails to users subscribed to this type of product List<String> subs = productService.getSubscribes(p.getType()); mailToSubs mails = new mailToSubs(); for (String s : subs) { mails.envoyerfacture(s.toString(), p.getImage().toString(), p.getId(), p.getTitre(), p.getPrix(), p.getDescription()); } } }
From source file:es.portizsan.twitrector.tasks.TweetReplyTask.java
License:Open Source License
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) { String message = null;//from w ww . j a va2 s . c om if (req.getParameter("message") != null) { message = req.getParameter("message"); } else { logger.log(Level.WARNING, "message is null."); return; } long inReplyToStatusId = 0; if (req.getParameter("statusId") != null) { try { inReplyToStatusId = Long.parseLong(req.getParameter("statusId")); } catch (NumberFormatException nfe) { logger.log(Level.WARNING, "Invalid statusId.", nfe); return; } } else { logger.log(Level.WARNING, "statusId is null."); return; } try { logger.info("repling: " + message + " , " + inReplyToStatusId); Twitter twitter = new TwitterService().getTwitterInstance(); StatusUpdate su = new StatusUpdate(message); su.setInReplyToStatusId(inReplyToStatusId); twitter.updateStatus(su); } catch (TwitterException te) { logger.log(Level.WARNING, "Failed to search tweets: ", te); } }
From source file:gohai.simpletweet.SimpleTweet.java
License:Apache License
/** * Send a tweet//from w ww .ja va2 s . co m * @param message message to send * @return partial URL of the tweet (e.g. "mrgohai/status/841086396194529280") */ public String tweet(String message) { try { StatusUpdate update = new StatusUpdate(message); Status status = twitter.updateStatus(update); User user = status.getUser(); return user.getScreenName() + "/status/" + status.getId(); } catch (TwitterException e) { System.err.println(e.getMessage()); throw new RuntimeException("Error posting tweet"); } }
From source file:gohai.simpletweet.SimpleTweet.java
License:Apache License
/** * Tweet an image/*from w w w .jav a 2 s . co m*/ * @param img PImage instance to attach * @param message message to send * @return partial URL of the tweet (e.g. "mrgohai/status/841086396194529280") */ public String tweetImage(PImage img, String message) { StatusUpdate update = new StatusUpdate(message); return tweetImage(img, update); }
From source file:Group5.Model.java
public static void Tweet(String inputTweet) throws TwitterException { //Your Twitter App's Consumer Key String consumerKey = "wK7lQLpl3t8xvIABqpgoJzYYd"; //Your Twitter App's Consumer Secret String consumerSecret = "4M5TgmNfS0EKeaSqna8eHTNaNi970Plq3dynX5gvYsh848j0mj"; //Your Twitter Access Token String accessToken = "829891753473892361-7jkKyXLYc6HOStzCPGjWOnVoAVNU7cd"; //Your Twitter Access Token Secret String accessTokenSecret = "ATidrzRzhVqAamuMbYiskcHBPSisB9MWsCsYYY2Bec4y9"; //Instantiate a re-usable and thread-safe factory TwitterFactory twitterFactory = new TwitterFactory(); //Instantiate a new Twitter instance Twitter twitter = twitterFactory.getInstance(); //setup OAuth Consumer Credentials twitter.setOAuthConsumer(consumerKey, consumerSecret); //setup OAuth Access Token twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); //Instantiate and initialize a new twitter status update StatusUpdate statusUpdate = new StatusUpdate( //your tweet or status message inputTweet);//ww w . ja va 2s . c o m //tweet or update status Status status = twitter.updateStatus(statusUpdate); //response from twitter server System.out.println("status.toString() = " + status.toString()); System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName()); System.out.println("status.getSource() = " + status.getSource()); System.out.println("status.getText() = " + status.getText()); System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities())); System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities())); }
From source file:it.baywaylabs.jumpersumo.twitter.TwitterListener.java
License:Open Source License
/** * This method is called when invoke <b>execute()</b>.<br /> * Do not invoke manually. Use: <i>new TwitterListener().execute("");</i> * * @param params//from w w w.j av a 2s .c o m */ @Override protected List<String> doInBackground(String... params) { Intelligence ai = new Intelligence(); try { User user = twitter.verifyCredentials(); Paging paging; if (idLastTwit != 0) paging = new Paging(idLastTwit + 1); else paging = new Paging(); paging.count(100); statuses = twitter.getMentionsTimeline(paging); if (statuses.size() != 0 && statuses != null) { Log.d(TAG, "Showing @" + user.getScreenName() + "'s mentions:"); Log.d(TAG, statuses.get(0).getText() + "-- ID: " + statuses.get(0).getId()); if (!"".equals(statuses.get(0).getText()) && licenses.size() == 0) { extractCommand(ai, statuses); Log.d(TAG, "Non ho licenze attive!"); } else if (!"".equals(statuses.get(0).getText()) && licenses.size() > 0 && f.boolContainsIgnoreCase(licenses, String.valueOf(statuses.get(0).getUser().getId()))) { extractCommand(ai, statuses); Log.i(TAG, "Seguo la lista delle licenze: " + licenses.toString()); } else { publishProgress(false); } if (deviceController != null) { Random r = new Random(); Interpreter interp = new Interpreter(deviceController); for (int i = 0; i < execute.size(); i++) { Log.d(TAG, "Seguenza istruzioni rilevate: " + execute.toString()); if (execute.size() >= 1 && "EXECUTE".equals(execute.get(i)) && f.getUrls(statuses.get(0).getText()).size() != 0) { String url = statuses.get(0).getURLEntities()[0].getExpandedURL(); // String url = f.getUrls(statuses.get(0).getText()).get(0); File folder = new File(Constants.DIR_ROBOT); Log.d(TAG, "URL Expanded: " + url); if (downloadFileUrl(url, folder)) { FileFilter ff = new FileFilter(); File[] list = folder.listFiles(ff); Log.e(TAG, "Lista file: " + list.length); if (list != null && list.length >= 1) { if (list[0].getName().endsWith(".csv") || list[0].getName().endsWith(".txt")) { String commandsList = ""; try { commandsList = f.getStringFromFile(list[0].getPath()); } catch (Exception e) { e.printStackTrace(); } Log.d(TAG, "Lista comandi: " + commandsList); interp.doListCommands(commandsList); list[0].delete(); if (i == execute.size() - 1) { try { StatusUpdate reply = new StatusUpdate( ai.actionAnswer(execute.get(i)).get( r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); twitter.updateStatus(reply); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } } } else if (execute.size() >= 1 && "PHOTO".equals(execute.get(i))) { // Download immagine e post nel tweet if (interp.doCommand(execute.get(i)) == 0) { String result = FTPDownloadFile(ip_host, 21, "anonymous", "", context); if (i == execute.size() - 1 && !"".equals(result)) { try { StatusUpdate reply = new StatusUpdate(ai.actionAnswer(execute.get(i)) .get(r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); File image = new File(Constants.DIR_ROBOT_IMG + "/" + result); Log.d(TAG, "Nome File immagine: " + image.getPath()); reply.media(image); twitter.updateStatus(reply); image.delete(); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } else if (execute.size() >= 1 && !"PHOTO".equals(execute.get(i)) && !"EXECUTE".equals(execute.get(i))) { if (interp.doCommand(execute.get(i)) == 0) { if (i == execute.size() - 1) { try { StatusUpdate reply = new StatusUpdate(ai.actionAnswer(execute.get(i)) .get(r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); twitter.updateStatus(reply); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } } } } Log.d(TAG, "ready exit"); } catch (TwitterException te) { te.printStackTrace(); Log.e(TAG, "Failed to get timeline: " + te.getMessage()); } return execute; }
From source file:it.baywaylabs.jumpersumo.utility.Finder.java
License:Open Source License
public int executePQ(PriorityQueue pq, ARDeviceController deviceController, List<twitter4j.Status> statuses, Twitter twitter) {/*w ww . ja v a 2s . com*/ if (pq != null && !pq.isEmpty() && deviceController != null) { Interpreter interpreter = new Interpreter(deviceController); Intelligence ai = new Intelligence(); Random r = new Random(); int indexExecutedFile = 0; while (pq.isEmpty()) { Command c = (Command) pq.peek(); Log.d(TAG, "Command Object: " + c.getPriority() + " -- " + c.getCmd()); if ("EXECUTE".equals(c.getCmd())) { if (statuses != null && twitter != null && this.getUrls(statuses.get(0).getText()).size() != 0) { String url = statuses.get(0).getURLEntities()[indexExecutedFile].getExpandedURL(); // String url = f.getUrls(statuses.get(0).getText()).get(0); File folder = new File(Constants.DIR_ROBOT); Log.d(TAG, "URL Expanded: " + url); if (downloadFileUrl(url, folder)) { FileFilter ff = new FileFilter(); File[] list = folder.listFiles(ff); if (list != null && list.length >= 1) { if (list[0].getName().endsWith(".csv") || list[0].getName().endsWith(".txt")) { String commandsList = ""; try { commandsList = this.getStringFromFile(list[0].getPath()); } catch (Exception e) { e.printStackTrace(); } Log.d(TAG, "Lista comandi: " + commandsList); interpreter.doListCommands(commandsList); list[0].delete(); if (pq.size() == 1) { try { StatusUpdate reply = new StatusUpdate(ai .actionAnswer( commandsList.split(";")[commandsList.length() - 1]) .get(r.nextInt(ai.actionAnswer( commandsList.split(";")[commandsList.length() - 1]) .size())) + "@" + statuses.get(0).getUser().getScreenName()); reply.setInReplyToStatusId(statuses.get(0).getId()); twitter.updateStatus(reply); } catch (TwitterException te) { Log.e(TAG, "Twitter Post Error: " + te.getMessage()); } } } } } pq.remove(); indexExecutedFile++; } } else { interpreter.doCommand(c.getCmd()); pq.remove(); } } return 0; } else if (pq.isEmpty()) { return 2; } else { return 1; } }
From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetMultiple.java
License:Open Source License
private final void tweet(final String index, final String screenName, final String str1, final String str2, final String str3) throws TwitterException { last_edited_editText.setEnabled(false); pref_app = PreferenceManager.getDefaultSharedPreferences(this); final String tweetstr = StringUtil.getTweetString(adapter.getTweetHeader(pref_app, str1), str2, adapter.getTweetfooter(pref_app, str3)); if (tweetstr.equals("")) { adapter.toast(getString(R.string.empty_tweettext)); return;/* ww w. j a v a 2s . co m*/ } try { adapter.getTwitter(adapter.checkIndexFromPrefTwtr(), false).updateStatus(new StatusUpdate(tweetstr)); adapter.toast(getString(R.string.done_tweet) + ": " + tweetstr + System.getProperty("line.separator") + System.getProperty("line.separator") + "[@" + screenName + "]"); last_edited_editText.setEnabled(true); final boolean pref_enable_ringtone_ontweet = pref_app.getBoolean("pref_enable_ringtone_ontweet", true); final String pref_ringtone_ontweet_updatetweetmultiple = pref_app .getString("pref_ringtone_ontweet_updatetweetmultiple", ""); if (pref_enable_ringtone_ontweet && (pref_ringtone_ontweet_updatetweetmultiple != null) && (pref_ringtone_ontweet_updatetweetmultiple.equals("") == false)) { final MediaPlayer mediaPlayer = MediaPlayer.create(UpdateTweetMultiple.this, Uri.parse(pref_ringtone_ontweet_updatetweetmultiple)); mediaPlayer.setLooping(false); mediaPlayer.seekTo(0); mediaPlayer.start(); } } catch (final TwitterException e) { if (e.exceededRateLimitation()) { try { adapter.getTwitter(adapter.checkIndexFromPrefTwtr(1), false) .updateStatus(new StatusUpdate(tweetstr)); adapter.toast( getString(R.string.done_tweet) + ": " + tweetstr + System.getProperty("line.separator") + System.getProperty("line.separator") + "[@" + screenName + "]"); last_edited_editText.setEnabled(true); } catch (final TwitterException e1) { } } adapter.toast(getString(R.string.cannot_access_twitter)); } catch (final Exception e) { adapter.toast(getString(R.string.exception)); } return; }