I'm already made a program. it's tweetclock.
it searching tweets within date/time keyword, and displaying whole thing like word clock.
you can see on browser "http://tweetclock.net/"
but the problem is super slow.. (especially on web) and also it's freeze when searching.
so I have to searching with asynchronous way.
I already searching on google, and only I can find the example code 'asyncUpdatedStatus' from twitter4j.org.
so I modified my code based on example code. but it's not working. it said 'unexpected token :('
I'm not heavy java developer. so it's hard to understand about listener.. but I tried..
please help.
this is my old one.
- Twitter twitter = new TwitterFactory().getInstance(); // twitter setting (not OAuth)
- String today_keyword = "오늘은";
- void search_today() {
- Query query = new Query(today_keyword);
- query.setRpp(10);
- QueryResult result;
- try {
- result = twitter.search(query);
- List<Tweet> tweet = result.getTweets();
- if(tweet.size() != 0) {
- int n = int(random(tweet.size()));
- today_tweets = tweet.get(n).getText();
- today_tweets = today_tweets.replaceAll("\\n", "");
- int index = today_tweets.indexOf(today_keyword);
- today_t_header = today_tweets.substring(0, index);
- today_t_footer = today_tweets.substring(index + today_keyword.length(), today_tweets.length());
- today_tweets_profileImageURL = tweet.get(n).getProfileImageUrl();
- today_tweets_profileImage = loadImage(today_tweets_profileImageURL, "png");
- }
- else {
- today_tweets = today_keyword;
- today_tweets_profileImage = loadImage("t.png");
- }
- }
- catch (TwitterException e) {
- e.printStackTrace();
- println(e.getRateLimitStatus());
- }
- }
this is the new code lines for async processing..
first I tried to modify code from TwitterFactory to AsyncTwitterFactory.
it seems like only one time change to Async*, then everything works fine(just my thinking..)
-
static final Object LOCK = new Object();
AsyncTwitterFactory factory = new AsyncTwitterFactory();AsyncTwitter twitter = factory.getInstance();
// override functionTwitterListener listener = new TwitterAdapter() {@Override void search(Query query) {System.out.println("Successfully searched");synchronized (LOCK) {LOCK.notify();}}
@Override void onException(TwitterException e, TwitterMethod method) {if (method == SEARCH) {e.printStackTrace();synchronized (LOCK) {LOCK.notify();}}else {// synchronized (LOCK) {// LOCK.notify();// }throw new AssertionError("Should not happen");}}};
twitter.addListener(listener); // processing said. unexpected token: (
1