List of usage examples for twitter4j TwitterStream retweet
TwitterStream retweet();
From source file:PrintRetweetStream.java
License:Apache License
/** * Main entry of this application./*www .j a v a 2s . co m*/ * * @param args arguments doesn't take effect with this example * @throws TwitterException when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(""); cb.setOAuthConsumerSecret(""); cb.setOAuthAccessToken(""); cb.setOAuthAccessTokenSecret(""); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @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.retweet(); }
From source file:org.wso2.carbon.inbound.custom.poll.TwitterStreamData.java
License:Open Source License
/** * Setting up a connection with Twitter Stream API with the given * credentials/* w w w . ja va 2 s .c om*/ * * @throws TwitterException */ private void setupConnection() throws TwitterException { if (log.isDebugEnabled()) { log.debug("Starting to setup the connection with the twitter streaming endpoint"); } ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken) .setOAuthAccessTokenSecret(accessSecret); StatusListener statusStreamsListener; UserStreamListener userStreamListener; SiteStreamsListener siteStreamslistener; TwitterStream twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); String twitterOperation = properties.getProperty(TwitterConstant.TWITTER_OPERATION); if (twitterOperation.equals(TwitterConstant.FILTER_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.FIREHOSE_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.LINK_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.SAMPLE_STREAM_OPERATION)) { statusStreamsListener = new StatusListenerImpl(); twitterStream.addListener(statusStreamsListener); } else if (twitterOperation.equals(TwitterConstant.USER_STREAM_OPERATION)) { userStreamListener = new UserStreamListenerImpl(); twitterStream.addListener(userStreamListener); } else if (twitterOperation.equals(TwitterConstant.SITE_STREAM_OPERATION)) { siteStreamslistener = new siteStreamsListenerImpl(); twitterStream.addListener(siteStreamslistener); } else { handleException("The operation :" + twitterOperation + " not found"); } /* Synchronously retrieves public statuses that match one or more filter predicates.*/ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.FILTER_STREAM_OPERATION)) { FilterQuery query = new FilterQuery(); if (languages != null) { query.language(languages); } if (tracks != null) { query.track(tracks); } if (follow != null) { query.follow(follow); } if (filterLevel != null) { query.filterLevel(filterLevel); } query.count(count); twitterStream.filter(query); } /* Returns a small random sample of all public statuses. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.SAMPLE_STREAM_OPERATION)) { if (languages != null) { if (languages.length == 1) { twitterStream.sample(languages[1]); } else { handleException("A language can be used for the sample operation"); } } twitterStream.sample(); } /* Asynchronously retrieves all public statuses.*/ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.FIREHOSE_STREAM_OPERATION)) { if (countParam != null) { twitterStream.firehose(count); } } /* User Streams provide a stream of data and events specific to the authenticated user.This provides to access the Streams messages for a single user. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.USER_STREAM_OPERATION)) { if (tracks != null) { twitterStream.user(tracks); } twitterStream.user(); } /* * Link Streams provide asynchronously retrieves all statuses containing 'http:' and 'https:'. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.LINK_STREAM_OPERATION)) { if (countParam != null) { twitterStream.links(count); } } /* * User Streams provide a stream of data and events specific to the * authenticated user.This provides to access the Streams messages for a * single user. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.RETWEET_STREAM_OPERATION)) { twitterStream.retweet(); } /* * Site Streams allows services, such as web sites or mobile push * services, to receive real-time updates for a large number of users. * Events may be streamed for any user who has granted OAuth access to * your application. Desktop applications or applications with few users * should use user streams. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.SITE_STREAM_OPERATION)) { twitterStream.site(withFollowings, follow); } }