Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Zoho Docs
Google Docs
Each Attachment size should not exceed 1MB.
Max no of attachments : 0
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
New to this Portal?
Click on Join Now to Sign Up
Join Now
Help
Feedback
Sign In
Processing Forum
Recent Topics
All Forums
Search All
Tags
Author
Advanced Search
Search
New Topic
Screen name:
icq4ever
icq4ever's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
anyone know twitter4j asynchronous searching?
[0Replies]
09-May-2012 04:09 AM
Forum:
Contributed Library Questions
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 function
TwitterListener 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: (
«Prev
Next »
Moderate user : icq4ever
Forum