List of usage examples for twitter4j TwitterStream setOAuthAccessToken
void setOAuthAccessToken(AccessToken accessToken);
From source file:at.illecker.sentistorm.spout.TwitterStreamSpout.java
License:Apache License
@Override public void open(Map config, TopologyContext context, SpoutOutputCollector collector) { m_collector = collector;/*from w ww .ja v a 2s . co m*/ m_tweetsQueue = new LinkedBlockingQueue<Status>(1000); // Optional startup sleep to finish bolt preparation // before spout starts emitting if (config.get(CONF_STARTUP_SLEEP_MS) != null) { long startupSleepMillis = (Long) config.get(CONF_STARTUP_SLEEP_MS); TimeUtils.sleepMillis(startupSleepMillis); } TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); // Set Listener twitterStream.addListener(new StatusListener() { @Override public void onStatus(Status status) { m_tweetsQueue.offer(status); // add tweet into queue } @Override public void onException(Exception arg0) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onStallWarning(StallWarning arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } }); // Set credentials twitterStream.setOAuthConsumer(m_consumerKey, m_consumerSecret); AccessToken token = new AccessToken(m_accessToken, m_accessTokenSecret); twitterStream.setOAuthAccessToken(token); // Filter twitter stream FilterQuery tweetFilterQuery = new FilterQuery(); if (m_keyWords != null) { tweetFilterQuery.track(m_keyWords); } // Filter location // https://dev.twitter.com/docs/streaming-apis/parameters#locations tweetFilterQuery.locations(new double[][] { new double[] { -180, -90, }, new double[] { 180, 90 } }); // any geotagged tweet // Filter language tweetFilterQuery.language(new String[] { m_filterLanguage }); twitterStream.filter(tweetFilterQuery); }
From source file:at.storm.spout.TwitterStreamSpout.java
License:Apache License
@SuppressWarnings("rawtypes") @Override//from w ww. j av a2 s . c o m public void open(Map config, TopologyContext context, SpoutOutputCollector collector) { m_collector = collector; m_tweetsQueue = new LinkedBlockingQueue<Status>(1000); // Optional startup sleep to finish bolt preparation // before spout starts emitting if (config.get(CONF_STARTUP_SLEEP_MS) != null) { long startupSleepMillis = (Long) config.get(CONF_STARTUP_SLEEP_MS); TimeUtils.sleepMillis(startupSleepMillis); } TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); // Set Listener twitterStream.addListener(new StatusListener() { @Override public void onStatus(Status status) { m_tweetsQueue.offer(status); // add tweet into queue } @Override public void onException(Exception arg0) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onStallWarning(StallWarning arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } }); // Set credentials twitterStream.setOAuthConsumer(m_consumerKey, m_consumerSecret); AccessToken token = new AccessToken(m_accessToken, m_accessTokenSecret); twitterStream.setOAuthAccessToken(token); // Filter twitter stream FilterQuery tweetFilterQuery = new FilterQuery(); if (m_keyWords != null) { tweetFilterQuery.track(m_keyWords); } // Filter location // https://dev.twitter.com/docs/streaming-apis/parameters#locations tweetFilterQuery.locations(new double[][] { new double[] { -180, -90, }, new double[] { 180, 90 } }); // any // geotagged // tweet // Filter language tweetFilterQuery.language(new String[] { m_filterLanguage }); twitterStream.filter(tweetFilterQuery); }
From source file:com.accumulobook.designs.graph.TwitterGraph.java
License:Apache License
public static void ingest(final String[] args, final BatchWriter writer, int seconds) throws Exception { String token = args[0];/*from w w w . ja v a 2 s.co m*/ String tokenSecret = args[1]; String consumerKey = args[2]; String consumerSecret = args[3]; TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addListener(new TGStatusListener(writer)); AccessToken accessToken = new AccessToken(token, tokenSecret); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); twitterStream.setOAuthAccessToken(accessToken); System.out.println("processing twitter stream ..."); twitterStream.sample(); Thread.sleep(seconds * 1000); System.out.println("shutting down twitter stream."); twitterStream.shutdown(); writer.flush(); }
From source file:com.cafeform.iumfs.twitterfs.TwitterFactoryAdapter.java
License:Apache License
public static void setUserStreamListener(String username, UserStreamListener listener) { // Invokde timeline retrieving thread. // Stream API (only home) // Thread created in TwitterStream.sample() TwitterStream twitterStream = streamFactory.getInstance(); twitterStream.setOAuthConsumer(Prefs.get("OAuthConsumerKey"), Prefs.get("consumerSecret")); twitterStream.setOAuthAccessToken(TwitterFactoryAdapter.getAccessToken(username)); twitterStream.addListener(listener); twitterStream.user();//from w ww. j av a2s .co m }
From source file:com.microsoft.example.TwitterSampleSpout.java
License:Apache License
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;// w w w . jav a2 s.c o m StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { queue.offer(status); } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { } @Override public void onTrackLimitationNotice(int i) { } @Override public void onScrubGeo(long l, long l1) { } @Override public void onException(Exception ex) { } @Override public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); twitterStream.addListener(listener); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); twitterStream.filter(query); } }
From source file:com.storm.demo.TwitterSampleSpout.java
License:Apache License
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<String>(1000); _collector = collector;/*from w ww . ja v a2 s. c om*/ // StatusListener listener = new StatusListener() { // // @Override // public void onStatus(Status status) { // System.out.println(DataObjectFactory.getRawJSON(status)); // queue.offer(status); // } // // @Override // public void onDeletionNotice(StatusDeletionNotice sdn) { // } // // @Override // public void onTrackLimitationNotice(int i) { // } // // @Override // public void onScrubGeo(long l, long l1) { // } // // @Override // public void onException(Exception ex) { // } // // @Override // public void onStallWarning(StallWarning arg0) { // // TODO Auto-generated method stub // // } // // }; RawStreamListener rawListener = new RawStreamListener() { @Override public void onMessage(String rawJSON) { //System.out.println(rawJSON); queue.offer(rawJSON); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); //twitterStream.addListener(listener); twitterStream.addListener(rawListener); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); twitterStream.filter(query); } }
From source file:com.twitstreet.twitter.AdsListenerMgrImpl.java
License:Open Source License
@Override public void start() { TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); Announcer announcer = announcerMgr.randomAnnouncerData(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override// w w w .jav a2 s .c o m public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { HashtagEntity[] hashtagEntities = status.getHashtagEntities(); String screenName = status.getUser().getScreenName(); User user = status.getUser(); if (user != null && (System.currentTimeMillis() - lastMessage > TEN_MIN)) { lastMessage = System.currentTimeMillis(); int action = (int) (ACTION_TYPES * Math.random()); switch (action) { case REGULAR_TWEET: LocalizationUtil lutil = LocalizationUtil.getInstance(); int sentenceSize = Integer .parseInt(lutil.get("announcer.sentence.size", LocalizationUtil.DEFAULT_LANGUAGE)); int random = (int) (Math.random() * sentenceSize); String rndMessage = lutil.get("announcer.sentence." + random, LocalizationUtil.DEFAULT_LANGUAGE); announcerMgr.announceFromRandomAnnouncer(rndMessage); break; case RETWEEET: announcerMgr.retweet(status.getId()); break; case FAVOURITE: announcerMgr.favourite(status.getId()); break; default: String message = constructAdsMessage(screenName, hashtagEntities, status.getUser().getLang()); announcerMgr.reply(message, status.getId()); break; } } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.twitstreet.twitter.FollowBackMgrImpl.java
License:Open Source License
@Override public void start() { Announcer announcer = announcerMgr.randomAnnouncerData(); twitterProxy = twitterProxyFactory.create(announcer.getAccessToken(), announcer.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override/*from w w w . java 2 s . c om*/ public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { if (System.currentTimeMillis() - lastFollow > FOLLOW_INTERVAL) { twitter4j.User user = status.getUser(); announcerMgr.follow(user.getId()); lastFollow = System.currentTimeMillis(); } // if(System.currentTimeMillis() - lastFollowDiabloBird > FOLLOW_INTERVAL/6){ // twitter4j.User user = status.getUser(); // announcerMgr.followForDiabloBird(user.getId()); // lastFollowDiabloBird = System.currentTimeMillis(); // } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.twitstreet.twitter.Welcome2ListenerMgrImpl.java
License:Open Source License
@Override public void start() { Announcer announcer = announcerMgr.randomAnnouncerData(); twitterProxy = twitterProxyFactory.create(announcer.getAccessToken(), announcer.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override// w w w .ja v a 2s . c om public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { UserMentionEntity[] userMentionEntities = status.getUserMentionEntities(); for (UserMentionEntity userMentionEntity : userMentionEntities) { idSet.add(userMentionEntity.getId()); if (idSet.size() >= TwitterProxyImpl.IDS_SIZE) { List<User> userList = twitterProxy.getTwUsers(new ArrayList<Long>(idSet)); if (userList != null) { for (User user : userList) { if (user.getFollowersCount() > MIN_FOLLOWER_COUNT_FOR_TREND) { Stock stock = new Stock(user); stockMgr.saveStock(stock); stockMgr.saveTrend(stock.getId()); } } } idSet.clear(); } } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:net.lacolaco.smileessence.twitter.TwitterApi.java
License:Open Source License
public TwitterStream getTwitterStream() { TwitterStream stream = new TwitterStreamFactory().getInstance(); stream.setOAuthAccessToken(new AccessToken(token, tokenSecret)); return stream; }