简体   繁体   中英

Twitter4j TwitterStream filter() not working to update parameters

I have a TwitterStream object:

static TwitterStream twitterStream = new TwitterStreamFactory().getInstance();

which I add a listener to, and some user ids to track (the user ids are correct, and this part works):

twitterStream.addListener(listener);
twitterStream.filter(new FilterQuery(followArray));

The problem, is that inside the listener, in onStatus(Status status) I want to add a user to track. I've tried this two ways, first by simply doing

twitterStream.filter(new FilterQuery(newArray));

where this newArray is the old one plus the new user id, and I've also tried calling

twitterStream.cleanUp();

before filter() . In both cases, the code appears to run, but then when I tweet from one of the followed accounts, I get the message

[Tue May 13 15:30:08 EDT 2014]Establishing connection.

and then the program terminates.

I can provide my full code if necessary, but any debugging help would be appreciated.

Sometimes you have to sleep the main thread for a period of time. Check whether you have the following code:

Thread.sleep(400000)

after

twitterStream.filter(new FilterQuery(newArray));

and before

twitterStream.cleanUp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM