I am using twitter4j to connect to the Stream API.
I understand that from this message Change the keywords of the Twitter stream filter without reopening the stream , it is impossible to change the keywords while the connection is open. I have to disconnect and change the filter predicate and reconnect it.
I would like to know if there is any sample code that will allow me to disable it, change keywords and reconnect it?
I am currently trying to do this in the StatusListener in onStatus (), where after X minutes have passed, it will change the keyword to "juice". But for me there is no way to close the connection and reconnect to the Stream API.
if (diff>=timeLapse) { StatusListener listener = createStatusListener(); track = "juice"; twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addListener(listener); FilterQuery fq = new FilterQuery(); fq.track(new String[] {track}); startTime=System.currentTimeMillis(); twitterStream.filter(fq); }
ktlim
source share