1 import java.io.BufferedReader;
2 import java.io.FileNotFoundException;
3 import java.io.IOException;
4 import java.io.InputStreamReader;
6 import java.util.logging.Level;
7 import java.util.logging.Logger;
9 import org.xml.sax.SAXParseException;
10 import twitter.action.TweetSearchResultGetter;
12 import twitter.log.TwitterLogManager;
13 import twitter.manage.TweetManager;
14 import twitter4j.Status;
15 import twitter4j.Twitter;
16 import twitter4j.TwitterException;
17 import twitter4j.TwitterFactory;
18 import twitter4j.conf.Configuration;
19 import twitter4j.conf.ConfigurationBuilder;
20 import twitter4j.http.AccessToken;
21 import twitter4j.http.RequestToken;
23 public class TestDriver {
24 private static final String CONSUMER_KEY = "tbo5erit2M2ZzN6n8tEYcA";
25 private static final String CONSUMER_SECRET = "tODurbdySLYU1pKjtB3MQTDRBGy562dHzVf7d62mm8";
34 * @return Twitterクラスのインスタンス<BR>
37 public static Twitter getInstance(String userId, String password) {
38 Configuration conf = getConfiguration();
40 TwitterFactory twitterfactory = new TwitterFactory(conf);
41 Twitter twitter = twitterfactory.getInstance(userId, password);
44 twitter.getOAuthAccessToken();
45 } catch (TwitterException e) {
57 * @return Twitterクラスのインスタンス<BR>
60 public synchronized static Twitter getOAuthAuthorizedInstance(String token, String token_secret) {
61 Configuration conf = getConfiguration();
62 TwitterFactory twitterfactory = new TwitterFactory(conf);
63 Twitter twitter = twitterfactory.getOAuthAuthorizedInstance(new AccessToken(token, token_secret));
67 } catch (TwitterException e) {
79 private static Configuration getConfiguration() {
80 ConfigurationBuilder confbuilder = new ConfigurationBuilder();
81 confbuilder.setOAuthConsumerKey(CONSUMER_KEY);
82 confbuilder.setOAuthConsumerSecret(CONSUMER_SECRET);
83 return confbuilder.build();
86 public static void main(String[] args) {
87 TweetManager tweetManager = new TweetManager();
88 TweetSearchResultGetter searchGetter = new TweetSearchResultGetter(tweetManager, "followme");
90 tweetManager.loginTwitter();
91 List<Status> status = searchGetter.getNewTweetData();
92 for (Status s : status) {
93 System.out.println(s);
96 System.out.println("---");
98 List<Status> status2 = searchGetter.getTweetData(5);
99 for (Status s : status2) {
100 System.out.println(s);
102 } catch (FileNotFoundException ex) {
103 Logger.getLogger(TestDriver.class.getName()).log(Level.SEVERE, null, ex);
104 ex.printStackTrace();
105 } catch (IOException ex) {
106 Logger.getLogger(TestDriver.class.getName()).log(Level.SEVERE, null, ex);
107 ex.printStackTrace();