List of usage examples for twitter4j Twitter updateStatus
Status updateStatus(String status) throws TwitterException;
From source file:org.opennms.netmgt.notifd.MicroblogNotificationStrategy.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . j ava 2 s . c o m public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String messageBody = buildMessageBody(arguments); Status response; final String baseURL = svc.getConfiguration().getClientURL(); LOG.debug("Dispatching microblog notification at base URL '{}' with message '{}'", baseURL, messageBody); try { response = svc.updateStatus(messageBody); } catch (TwitterException e) { LOG.error("Microblog notification failed at service URL '{}'", baseURL, e); return 1; } LOG.info("Microblog notification succeeded: update posted with ID {}", response.getId()); return 0; }
From source file:org.opennms.netmgt.notifd.MicroblogReplyNotificationStrategy.java
License:Open Source License
/** {@inheritDoc} */ @Override//from www.j a va 2 s . c om public int send(final List<Argument> arguments) { final Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); Status response; if (destUser == null || "".equals(destUser)) { LOG.error( "Cannot send a microblog reply notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } // In case the user tried to be helpful, avoid a double @@ if (destUser.startsWith("@")) destUser = destUser.substring(1); final String fullMessage = String.format("@%s %s", destUser, buildMessageBody(arguments)); LOG.debug("Dispatching microblog reply notification at base URL '{}' with message '{}'", svc.getConfiguration().getClientURL(), fullMessage); try { response = svc.updateStatus(fullMessage); } catch (final TwitterException e) { LOG.error("Microblog notification failed at service URL '{}'", svc.getConfiguration().getClientURL(), e); return 1; } LOG.info("Microblog reply notification succeeded: reply update posted with ID {}", response.getId()); return 0; }
From source file:org.orcid.core.manager.impl.OrcidSocialManagerImpl.java
License:Open Source License
/** * Tweet a message to the specified profile * /*www .j a v a2s.c om*/ * @param entity * An entity containing the user information and the twitter * credentials * @return true if it was able to tweet the updates * */ @SuppressWarnings("unchecked") private boolean tweet(OrcidSocialEntity entity) { String jsonCredentials = decrypt(entity.getEncryptedCredentials()); Map<String, String> credentials = (HashMap<String, String>) JSON.parse(jsonCredentials); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(twitterKey, twitterSecret); AccessToken accessToken = new AccessToken(credentials.get(TWITTER_USER_KEY), credentials.get(TWITTER_USER_SECRET)); twitter.setOAuthAccessToken(accessToken); try { twitter.updateStatus(buildUpdateMessage(entity.getId().getOrcid())); } catch (Exception e) { LOGGER.error("Unable to tweet on profile {}", entity.getId().getOrcid()); return false; } return true; }
From source file:org.osframework.maven.plugins.twitter.TweetMojo.java
License:Apache License
protected void executeInTwitter(Twitter twitter) throws MojoExecutionException, MojoFailureException { try {//from www . j a va 2 s. com Status status = twitter.updateStatus(getMessage()); getLog().info("Sent tweet: " + status.getText()); logStatus(status); } catch (TwitterException te) { throw new MojoFailureException("Could not send tweet", te); } }
From source file:org.ow2.frascati.akka.fabric.peakforecast.lib.TwitterImpl.java
License:Open Source License
@Override public void updateStatus(String message) { try {//from w w w . j a va 2s. c om ConfigurationBuilder cb = new ConfigurationBuilder(); //info OAuth settings de l'application twitter tweetpeakforecast enregistr par l'utilisateur @peakforecast cb.setDebugEnabled(true).setOAuthConsumerKey("0PqersXnGOn7AirB13jszw") .setOAuthConsumerSecret("r3qyCuhmwRI90JY04kqcYtn5yEl6yaW1UoRhAY08Q") .setOAuthAccessToken("1598158057-epoKcN3Lfz405zjNZQ2rl5cx74lthvBZ93cCsfj") .setOAuthAccessTokenSecret("6YwDPdjS7OpqDHb6PsmW0beOjCgjITzDGYV89gtQU"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); Status status = twitter.updateStatus(message); System.out.println("Successfully updated the status to [" + status.getText() + "]."); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.rhq.enterprise.server.plugins.alertMicroblog.MicroblogSender.java
License:Open Source License
@Override public SenderResult send(Alert alert) { SenderResult result;/*from w w w. j a v a2s . co m*/ String consumerKey = preferences.getSimpleValue("consumerKey", CONS_KEY); String consumerSecret = preferences.getSimpleValue("consumerSecret", CONS_SECRET); String accessTokenFilePath = preferences.getSimpleValue("accessTokenFilePath", "/path/to/token.ser"); try { TwitterFactory tFactory = new TwitterFactory(); AccessToken accessToken = restoreAccessToken(accessTokenFilePath); log.debug("loading accessToken from " + accessTokenFilePath); log.debug("token: [" + accessToken.getToken() + "]"); log.debug("tokenSecret: [" + accessToken.getTokenSecret() + "]"); Twitter twitter = tFactory.getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); twitter.setOAuthAccessToken(accessToken); AlertManagerLocal alertManager = LookupUtil.getAlertManager(); StringBuilder b = new StringBuilder("Alert "); b.append(alert.getId()).append(":'"); // Alert id b.append(alert.getAlertDefinition().getResource().getName()); b.append("' ("); b.append(alert.getAlertDefinition().getResource().getId()); b.append("): "); b.append(alertManager.prettyPrintAlertConditions(alert, true)); b.append("-by " + this.alertParameters.getSimpleValue("twittedBy", "@RHQ")); // TODO not for production :-) // TODO use some alert url shortening service String msg = b.toString(); if (msg.length() > 140) msg = msg.substring(0, 140); Status status = twitter.updateStatus(msg); result = SenderResult.getSimpleSuccess("Send notification - msg-id: " + status.getId()); } catch (TwitterException e) { log.warn("Notification via Microblog failed!", e); result = SenderResult.getSimpleFailure("Sending failed :" + e.getMessage()); } catch (IOException e) { log.error("Notification via Microblog failed!", e); result = SenderResult.getSimpleFailure("Sending failed :" + e.getMessage()); } return result; }
From source file:org.rhq.plugins.twitter.TwitterComponent.java
License:Open Source License
/** * Implementation of the OperationFacet//from w ww . jav a 2 s. c om * Sends a tweet * @param name the name of the operation * @param configuration parameters of the operation * @return result of the operation * @throws Exception If anything goes wrong */ public OperationResult invokeOperation(String name, Configuration configuration) throws Exception { if (name != null && name.equals("postStatus")) { if (username == null || password == null) { throw new IllegalArgumentException("User or password were not set"); } String message = configuration.getSimpleValue("message", null); Twitter twitter = createTwitterInstance(); Status status = twitter.updateStatus(message); @SuppressWarnings({ "UnnecessaryLocalVariable" }) OperationResult result = new OperationResult("Posted " + status.getText()); return result; } throw new UnsupportedOperationException("Operation " + name + " is not valid"); }
From source file:org.sakaiproject.profile2.logic.ProfileExternalIntegrationLogicImpl.java
License:Educational Community License
/** * {@inheritDoc}/*from ww w . j ava 2 s . c o m*/ */ public void sendMessageToTwitter(final String userUuid, String message) { //setup class thread to call later class TwitterUpdater implements Runnable { private Thread runner; private String userUuid; private String userToken; private String userSecret; private String message; public TwitterUpdater(String userUuid, String userToken, String userSecret, String message) { this.userUuid = userUuid; this.userToken = userToken; this.userSecret = userSecret; this.message = message; runner = new Thread(this, "Profile2 TwitterUpdater thread"); runner.start(); } //do it! public synchronized void run() { //global config Map<String, String> config = getTwitterOAuthConsumerDetails(); //token for user AccessToken accessToken = new AccessToken(userToken, userSecret); //setup TwitterFactory factory = new TwitterFactory(); Twitter twitter = factory.getInstance(); twitter.setOAuthConsumer(config.get("key"), config.get("secret")); twitter.setOAuthAccessToken(accessToken); try { twitter.updateStatus(message); log.info("Twitter status updated for: " + userUuid); //post update event sakaiProxy.postEvent(ProfileConstants.EVENT_TWITTER_UPDATE, "/profile/" + userUuid, true); } catch (TwitterException e) { log.error( "ProfileLogic.sendMessageToTwitter() failed. " + e.getClass() + ": " + e.getMessage()); } } } //is twitter enabled if (!sakaiProxy.isTwitterIntegrationEnabledGlobally()) { return; } //get user info ExternalIntegrationInfo info = getExternalIntegrationInfo(userUuid); String token = info.getTwitterToken(); String secret = info.getTwitterSecret(); if (StringUtils.isBlank(token) || StringUtils.isBlank(secret)) { return; } //PRFL-423 limit to 140 chars //Hardcoded limit because 140 is the Twitter requirement so no need to make configurable message = ProfileUtils.truncate(message, 140, false); //instantiate class to send the data new TwitterUpdater(userUuid, token, secret, message); }
From source file:org.sevenleaves.droidsensor.TwitterUtils.java
License:Apache License
/** * @param device/*from w ww . j a v a2 s. c o m*/ * @param settings * @return * @throws TwitterException */ public static String tweetDeviceFound(String address, String name, String id, String message, String deviceClass, SettingsManager settings) throws TwitterException { String template = settings.getUserTemplate(); String target = id; boolean isUser = true; if (target == null) { target = name; template = settings.getDeviceTemplate(); isUser = false; } if (target != null && target.startsWith("@")) { target = target.substring(1); template = settings.getPassedDeviceTemplate(); if (target.equals(settings.getTwitterId())) { template = settings.getPassedDeviceAgainTemplate(); } isUser = false; } String forNotify; String text = template.replace("$id", target); // api??????? // if (template.contains("$name")) { // // User user = twitter.showUser(id); // String name = user.getName(); // text = text.replace("$name", name); // } if (text.contains("$device")) { if (name == null) { return null; } text = text.replace("$device", deviceClass); } if (text.contains("$message")) { if (name == null) { return null; } forNotify = text.replace("$message", ""); if (isEmpty(message)) { text = text.replace("$message", ""); } else { text = text.replace("$message", " - " + message + " - "); } } else { forNotify = text; } if (text.contains("$tags")) { text = text.replace("$tags", (settings.getTags().startsWith(" ") ? "" : " ") + settings.getTags()); forNotify = forNotify.replace("$tags", ""); } List<Twitter> twitters = createTwitters(settings, isUser); for (int i = 0; i < twitters.size(); ++i) { Twitter t = twitters.get(i); t.updateStatus(text); } return forNotify; }
From source file:org.springframework.social.showcase.twitter.connect.TwitterApiAdapter.java
License:Apache License
@Override public void updateStatus(Twitter api, String message) { try {//from w ww .j a v a 2 s . com api.updateStatus(message); } catch (TwitterException e) { } }