List of usage examples for twitter4j StatusUpdate StatusUpdate
public StatusUpdate(String status)
From source file:cmu.edu.homework.mediaUpload.TwitterVideoUpload.java
License:Apache License
@Override public String upload(File video) throws TwitterException { return twitter.updateStatus(new StatusUpdate("").media(video)).getText(); }
From source file:cmu.edu.homework.mediaUpload.TwitterVideoUpload.java
License:Apache License
@Override public String upload(String videoFileName, InputStream videoBody) throws TwitterException { return twitter.updateStatus(new StatusUpdate("").media(videoFileName, videoBody)).getText(); }
From source file:cmu.edu.homework.mediaUpload.TwitterVideoUpload.java
License:Apache License
@Override public String upload(String videoFileName, InputStream videoBody, String message) throws TwitterException { return twitter.updateStatus(new StatusUpdate(message).media(videoFileName, videoBody)).getText(); }
From source file:com.amandine.twitterpostforcoucou.Tweet.java
private void publishStatusUpdateWithMedia(String message) throws MalformedURLException, IOException { Status status = null;//from ww w. j av a 2 s. c o m try { Twitter twitter = new TwitterFactory().getInstance(); try { RequestToken requestToken = twitter.getOAuthRequestToken(); AccessToken accessToken = null; while (null == accessToken) { logger.fine("Open the following URL and grant access to your account:"); logger.fine(requestToken.getAuthorizationURL()); try { accessToken = twitter.getOAuthAccessToken(requestToken); } catch (TwitterException te) { if (401 == te.getStatusCode()) { logger.severe("Unable to get the access token."); } else { te.printStackTrace(); } } } logger.log(Level.INFO, "Got access token."); logger.log(Level.INFO, "Access token: {0}", accessToken.getToken()); logger.log(Level.INFO, "Access token secret: {0}", accessToken.getTokenSecret()); } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is not set. if (!twitter.getAuthorization().isEnabled()) { logger.severe("OAuth consumer key/secret is not set."); return; } } //Instantiate and initialize a new twitter status update StatusUpdate statusUpdate = new StatusUpdate(message); //attach any media, if you want to statusUpdate.setMedia( //title of media "Amandine Leforestier Spring Summer 2015 white", new URL("https://issuu.com/kadiemurphy/docs/volume_xxi_issuu/52?e=0").openStream()); //tweet or update status status = twitter.updateStatus(statusUpdate); //Status status = twitter.updateStatus(message); logger.log(Level.INFO, "Successfully updated the status to [{0}].", status.getText()); } catch (TwitterException te) { te.printStackTrace(); logger.log(Level.SEVERE, "Failed to get timeline: {0}", te.getMessage()); } }
From source file:com.amandine.twitterpostforcoucou.Tweet.java
public void tweetMessageToUser(String username, String hashtags, String imageUrl, String targetUrl, String twitterid) {/* ww w .j a v a2 s .co m*/ Twitter twitterHandle = this.getTwitter(); //Instantiate and initialize a new twitter status update String message = username + " " + targetUrl + " " + hashtags + " #amandineleforestier"; StatusUpdate statusUpdate = new StatusUpdate(message); try { //attach any media, if you want to statusUpdate.setMedia(//title of media "Amandine Leforestier Athleasure Sport-Chic Autumn Winter 2015 http://shop.amandineleforestier.fr", new URL(imageUrl).openStream()); } catch (MalformedURLException ex) { logger.log(Level.SEVERE, "Bad image Url {0}", ex.getMessage()); } catch (IOException ex) { logger.log(Level.SEVERE, "Cannot open Url {0}", ex.getMessage()); } //tweet or update status Status status = null; try { status = twitterHandle.updateStatus(statusUpdate); logTheStatusUpdate(twitterid, message, imageUrl, targetUrl); } catch (TwitterException te) { logger.log(Level.SEVERE, "Failed to get timeline: {0}", te.getMessage()); } //Status status = twitter.updateStatus(message); if (status != null) { logger.log(Level.INFO, "Successfully updated the status to [{0}].", status.getText()); } else { logger.log(Level.SEVERE, "Status update failed [{0}].", status); } }
From source file:com.amazonbird.db.data.Announcer.java
License:Open Source License
public long reply(String message, long statusId) throws Exception { long replyStatus = -1; try {/* www. j a va 2 s . c o m*/ Status status = getTwitterProxy().updateStatus(new StatusUpdate("message").inReplyToStatusId(statusId)); replyStatus = status.getId(); } catch (TwitterException e) { logger.error("Error while replying: " + statusId + " Announcer: " + screenName); } return replyStatus; }
From source file:com.appspot.bitlyminous.handler.twitter.NearByHandler.java
License:Apache License
@Override public StatusUpdate execute(Status tweet) { GeoLocation geoLocation = tweet.getGeoLocation(); String text = getMentionText(tweet); if (geoLocation == null) { StatusUpdate reply = new StatusUpdate( ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.noLocation", new String[] { "@" + tweet.getUser().getScreenName() })); reply.setInReplyToStatusId(tweet.getId()); return reply; } else {//from www . jav a 2s. c o m try { GeoQuery query = new GeoQuery(geoLocation); List<Tip> nearbyTips = getFoursquareGateway() .getNearbyTips(new com.appspot.bitlyminous.entity.GeoLocation(geoLocation.getLatitude(), geoLocation.getLongitude()), 1); String status = buildTipsStatus(nearbyTips); if (nearbyTips.isEmpty()) { List<Venue> nearbyVenues = new ArrayList<Venue>(); if (text != null) { nearbyVenues = getFoursquareGateway().getNearbyVenues( new com.appspot.bitlyminous.entity.GeoLocation(geoLocation.getLatitude(), geoLocation.getLongitude()), text, 1); } status = status + buildVenuesStatus(nearbyVenues); if (nearbyVenues.isEmpty()) { List<Place> nearbyPlaces = getTwitterClient().getNearbyPlaces(query); status = status + buildPlacesStatus(nearbyPlaces); } } status = "@" + tweet.getUser().getScreenName() + " " + status; StatusUpdate reply = new StatusUpdate(status); reply.setInReplyToStatusId(tweet.getId()); return reply; } catch (Exception e) { logger.log(Level.SEVERE, "Error while getting nearby places", e); } return null; } }
From source file:com.appspot.bitlyminous.handler.twitter.RetweetRelatedTweetsHandler.java
License:Apache License
@Override public StatusUpdate execute(Status tweet) { try {/*from w w w . j a va 2s . c om*/ WebSearchQuery webSearchQuery = getGoogleWebSearchQuery(); webSearchQuery.withCustomeSearchEngineId(ApplicationConstants.GOOGLE_API_CSE); List<Url> urls = context.getUrls(); for (Url entity : urls) { // List<Tweet> relatedTweets = new ArrayList<Tweet>(); List<String> tags = entity.getTags(); if (!tags.isEmpty()) { List<WebResult> relatedTweets = webSearchQuery.withQuery(createQuery(tags)).list(); // List<Tweet> tweets = getTweetsFromCSE(results); // relatedTweets.addAll(tweets); relatedTweets = getBestMatches(tweet, relatedTweets, 1); if (!relatedTweets.isEmpty()) { StatusUpdate reply = new StatusUpdate(buildStatus(tweet, relatedTweets)); reply.setInReplyToStatusId(tweet.getId()); return reply; } } } } catch (Exception e) { logger.log(Level.SEVERE, "Error while persisting urls.", e); } return null; }
From source file:com.appspot.bitlyminous.handler.twitter.ScanLinkHandler.java
License:Apache License
@Override public StatusUpdate execute(Status tweet) { try {//from w w w. j a v a 2 s. com List<String> shortUrls = extractBitlyUrls(tweet.getText()); if (!shortUrls.isEmpty()) { Set<Url> longUrls = getBitlyClient() .call(Bitly.expand(shortUrls.toArray(new String[shortUrls.size()]))); GoogleSafeBrowsingGateway gateway = getGoogleSafeBrowsingGateway(); for (Url url : longUrls) { if (!isEmpty(url.getLongUrl())) { if (gateway.isBlacklisted(url.getLongUrl())) { StatusUpdate reply = new StatusUpdate(ApplicationResources.getLocalizedString( "com.appspot.bitlyminous.message.badurl", new String[] { "@" + tweet.getUser().getScreenName(), trimText(tweet.getText(), 20), ApplicationConstants.GOOGLE_SAFE_BROWSING_REF_URL })); reply.setInReplyToStatusId(tweet.getId()); return reply; } if (gateway.isMalwarelisted(url.getLongUrl())) { StatusUpdate reply = new StatusUpdate(ApplicationResources.getLocalizedString( "com.appspot.bitlyminous.message.badurl", new String[] { "@" + tweet.getUser().getScreenName(), trimText(tweet.getText(), 20), ApplicationConstants.GOOGLE_SAFE_BROWSING_REF_URL })); reply.setInReplyToStatusId(tweet.getId()); return reply; } } } } } catch (Exception e) { logger.log(Level.SEVERE, "Error while scanning urls.", e); } return null; }
From source file:com.appspot.bitlyminous.handler.twitter.SearchHandler.java
License:Apache License
@Override public StatusUpdate execute(Status tweet) { GoogleSearchQueryFactory factory = GoogleSearchQueryFactory .newInstance(ApplicationConstants.GOOGLE_API_KEY); WebSearchQuery query = factory.newWebSearchQuery(); query.setReferrer(ApplicationConstants.GOOGLE_API_REFERER); PagedList<WebResult> response = query.withQuery(getMentionText(tweet)).list(); if (response.isEmpty()) { return null; } else {/*from w ww . ja va 2 s. c om*/ StatusUpdate update = new StatusUpdate( "@" + tweet.getUser().getScreenName() + " " + buildStatus(response.get(0))); update.setInReplyToStatusId(tweet.getId()); return update; } }