List of usage examples for twitter4j.auth AccessToken AccessToken
public AccessToken(String token, String tokenSecret)
From source file:TwitterPlanet.java
License:Open Source License
private static AccessToken loadAccessToken() { return new AccessToken(AccessToken, AccessTokenSecret); }
From source file:DumpRetrievedTweet.java
private void GetTweetData() throws TwitterException, IOException { System.out.println("Seting up twitter"); Twitter twitter = new TwitterFactory().getInstance(); // String CONSUMER_KEY = "9zVRlQTXlTKf4QeYMiucyXqg9"; // String CONSUMER_SECRET = "xH0H2SfcXj914z1DGB7HgZZ012ntSqRbfnLFw5A6v1TB94Y2O1"; // String TWITTER_TOKEN = "753222147695259648-QnzInB98PtwpFb75dqlP1J7SSOQMcMX"; // String TWITTER_TOKEN_SECRET = "uxJHGE1e2kFBJYoNRRFfy5gBLXYaRrzCUycRncSkoLsle"; // String CONSUMER_KEY = "nNV9KxWFVmdI0a2shhJImcEGk"; // String CONSUMER_SECRET = "I4AvaGOZRFtLFTqAkpKrfFOnV13Ej2seiwnNQ47z0qE9ORoBhW"; // String TWITTER_TOKEN = "753222147695259648-kY3Gq1O6FqHw6LQViuTQAhLbEQLZRZX"; // String TWITTER_TOKEN_SECRET = "a6hsmYipeGvqJcrIUUZah4ZhH7B8wbY77hqNWwojQysiO"; // String CONSUMER_KEY = "PBMKK9P2YD9MFgDfdANQt2Zzc"; // String CONSUMER_SECRET = "ldB0FybCQIjfYLzuYE4CeGtvcevaSkFxPENGbFd19Yn2crXa5R"; // String TWITTER_TOKEN = "753222147695259648-ZWqj3CvdQAXeVl9zfa71BCRcxeD2yAi"; // String TWITTER_TOKEN_SECRET = "1bypYSL1D1t1Gt6nQLwEbyRg5rniOUHfJhTYuVWYWvAvP"; // String CONSUMER_KEY = "tf0Cbp3ZQcJh9vwkQ9vInw6WS"; // String CONSUMER_SECRET = "gRmcjuqrSH40K47CkRFEO5OVthUtExEW7xrZU2oWiRcpPmzRz9"; // String TWITTER_TOKEN = "126239739-qaXgO4urp91PXLT2RgkxlyONwAQyXnq236dhqtTe"; // String TWITTER_TOKEN_SECRET = "AIykIeAKGFHRucTPgNYZd9bqdbZEJQhMsF5cGiyBLUII7"; String CONSUMER_KEY = "EmmSsTEML5XrB3SYBUOOKxqn6"; String CONSUMER_SECRET = "J1TrjmcqhBd1cURBTjUCwNqcf5IxCfdInAs74TVT9axvSwLnlJ"; String TWITTER_TOKEN = "126239739-ktoaE8NhM4S9CjFhrktTdpuvY7fkbqj1nYxfaQsD"; String TWITTER_TOKEN_SECRET = "a5fFQbKO9meoqnY31wwlZF0nqDHtqfxlwUla1uaAT8Y0p"; twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); AccessToken accesstoken = new AccessToken(TWITTER_TOKEN, TWITTER_TOKEN_SECRET); twitter.setOAuthAccessToken(accesstoken); writer.write("\n"); for (int i = 0; i < tweet_ids.size(); i++) { Long tweet_id = tweet_ids.get(i); System.out.println("[" + i + "] Getting Tweet id " + tweet_id); Status status = twitter.showStatus((long) tweet_ids.get(i)); if (status == null) { System.out.println("[FAILED] Doesnot exist twitter with tweet id : " + tweet_id); } else {//from ww w .j a v a 2 s .com System.out.println("status asli : " + status.getText()); writer.write(tweet_id + "\t" + status.getText().replaceAll("\n", " ")); writer.write("\n"); updateIsLabelledAnotator3(tweet_id); } } }
From source file:TwitterPull.java
private void init() { this.twitterFactory = new TwitterFactory(); this.twitter = this.twitterFactory.getInstance(); this.twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); this.twitter.setOAuthAccessToken(new AccessToken(DEFAULT_ACCESS_TOKEN, DEFAULT_ACCESS_TOKEN_SECRET)); }
From source file:GetTweetsAndSaveToFile.java
License:Apache License
/** * Usage: java twitter4j.examples.user.ShowUser [screen name] * * @param args message/*from w w w . j a v a 2 s . c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.user.ShowUser [screen name]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer("men2JyLEaAsxcbfmgzOAwUnTp", "2AGN0ie9TfCDJyWeH8qhTLtMhqRvRlNBtQU3lAP2M8k3Xk1KWl"); RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Authorization URL: \n" + requestToken.getAuthorizationURL()); AccessToken accessToken = new AccessToken("2811255124-zigkuv8MwDQbr5s9HdjLRSbg8aCOyxeD2gYGMfH", "D7jFABWHQa8QkTWwgYj1ISUbWP8twdfbzNgYkXI3jwySR"); twitter.setOAuthAccessToken(accessToken); /* BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(requestToken); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } */ System.out.println("Got access token."); System.out.println("Access token: " + accessToken.getToken()); System.out.println("Access token secret: " + accessToken.getTokenSecret()); User user = twitter.showUser(args[0]); if (user.getStatus() != null) { System.out.println("@" + user.getScreenName() + " - " + user.getStatus().getText()); } else { // the user is protected System.out.println("@" + user.getScreenName()); } FileWriter file = new FileWriter("./" + user.getScreenName() + "_Tweets.txt"); List<Status> list = twitter.getHomeTimeline(); for (Status each : list) { file.write("Sent by: @" + each.getUser().getScreenName() + " - " + each.getUser().getName() + "---" + each.getText() + "\n"); } file.close(); System.exit(0); } catch (Exception te) { te.printStackTrace(); System.exit(-1); } }
From source file:MyUpdateTweetTimeToDB.java
public void GetTweetTime() { Twitter twitter = new TwitterFactory().getInstance(); String CONSUMER_KEY = "4enxNevEGWMqBuKzcJoQ"; String CONSUMER_SECRET = "UUDCNSvkFoZRaRUV4b8eHBcgR2N1LSrHXX7IELxdIk"; String TWITTER_TOKEN = "470084145-qwjAlIxq7GFB1I62TO5ebyoO10tXgUuZJfgTLu7G"; String TWITTER_TOKEN_SECRET = "9y47ww1xk0Nc5DhL9ZW0HOC6Qoig2wP101tOjsERnqNNv"; twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); AccessToken accesstoken = new AccessToken(TWITTER_TOKEN, TWITTER_TOKEN_SECRET); twitter.setOAuthAccessToken(accesstoken); Iterator iterator = tweet_id_to_time.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry pair = (Map.Entry) iterator.next(); try {/* w ww.ja v a 2 s . co m*/ Status status = twitter.showStatus((long) pair.getKey()); if (status == null) { System.out.println("Doesnot exist twitter with tweet id : " + pair.getKey()); } else { tweet_id_to_time.put((Long) pair.getKey(), status.getCreatedAt().getTime()); } } catch (TwitterException e) { tweet_id_to_time.put((Long) pair.getKey(), 1L); e.printStackTrace(); } System.out.println("Id : " + pair.getKey() + "value " + pair.getValue()); } }
From source file:algo.ad.feeder.TwitterStreamSpout.java
License:Apache License
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;/* w ww .jav a 2 s . c o m*/ startTime = System.currentTimeMillis(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { long elapsedTime = System.currentTimeMillis() - startTime; //System.out.println("*************elapsedTime:" + elapsedTime); if (elapsedTime > keywordRefreshInterval) { /// System.out.println("*************Changing Query:"); // Update the keyword list//////////////////// String[] temp_keywords = DatabaseHelper.getKeywordsFromDB(tweetsJDBCTemplate, DB_BASE_URL, DB_NAME, MAX_NUMBER_OF_QUERIES); if (!keyWords.equals(temp_keywords)) { keyWords = temp_keywords; FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } // ///////////////////////////////////// startTime = System.currentTimeMillis(); } 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 = new TwitterStreamFactory(new ConfigurationBuilder().setJSONStoreEnabled(true).build()) .getInstance(); _twitterStream.addListener(listener); _twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); _twitterStream.setOAuthAccessToken(token); keyWords = DatabaseHelper.getKeywordsFromDB(tweetsJDBCTemplate, DB_BASE_URL, DB_NAME, MAX_NUMBER_OF_QUERIES); if (keyWords.length == 0) { _twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } }
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 w w .j a v a2 s . com*/ 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//ww w . jav a2 s . com 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:au.com.tyo.services.sn.twitter.SNTwitter.java
License:Apache License
public void createInstance() { synchronized (this) { try {//from w w w . j a va 2 s.c o m if (hasSecret()) { AccessToken accessToken = new AccessToken(secretOAuth.getToken().getToken(), secretOAuth.getToken().getSecret()); Configuration conf = new ConfigurationBuilder().setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerKeySecret).setOAuthAccessToken(accessToken.getToken()) .setOAuthAccessTokenSecret(accessToken.getTokenSecret()).build(); OAuthAuthorization auth = new OAuthAuthorization(conf); twitter = new TwitterFactory().getInstance(auth); authenticated = true; } } catch (Exception ex) { authenticated = false; twitter = null; } try { /* * it is better to use the id, because people would change their name */ long sourceId = Integer.valueOf(secretOAuth.getId().getToken()); user = twitter.showUser(sourceId); // user = twitter.showUser(userInfo.getName()); secretOAuth.getId().setToken(String.valueOf(user.getId())); secrets.save(secretOAuth.getId()); userInfo.setName(user.getScreenName()); alias.setName(user.getName()); saveUserInfo(); saveAlias(); userProfileImageUrl = getUserAvatarUrl(); } catch (Exception ex) { } } }
From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.twitter.AddUsersToFollowToDatabase.java
License:Apache License
public static void insert() throws DaoException { twitter = TwitterFactory.getSingleton(); AccessToken accessToken = new AccessToken(TwitterCredentialProvider.getAccessToken(), TwitterCredentialProvider.getAccessSecret()); twitter.setOAuthConsumer(TwitterCredentialProvider.get0AuthConsumerKey(), TwitterCredentialProvider.get0AuthConsumerSecret()); twitter.setOAuthAccessToken(accessToken); for (String user : users) { try {//from ww w.j a va 2 s . co m long id = getId(user); dao.addUserToFollow(user, id); } catch (TwitterException ex) { logger.error(ex); } } }