我是twitter4j和处理新手。
我想从单词列表中获取最新搜索到的单词。我希望将它存储在将要查询的变量中。 这样:
PossibleWords[] ={"sad","happy","joyful"}
然后我想要一个字符串变量searchString来保存包含该数组中单词的最新推文。例如,如果刚刚发布了悲伤,我想收到那条推文。所以我需要测试数组中的任何单词是否在最新的推文中。
从概念上讲,我理解这一点,但任何人都对编程有什么建议吗?这在处理中使用twitter4j 3
答案 0 :(得分:1)
您应该使用Twitter Streaming API,查看下面粘贴的代码块:
private void GetTweetsByKeywords()
{
TwitterStream twitterStream = new TwitterStreamFactory(config).getInstance();
StatusListener statusListener = new StatusListener() {
private int count = 0;
private long originalTweetId = 0;
@Override
public void onStatus(Status status) {
// Here do whatever you want with the status object that is the
// tweet you got
} //end of the onStatus()
}; //end of the listener
FilterQuery fq = new FilterQuery();
String keywords[] = {"sad","happy","joyful"};
fq.track(keywords);
twitterStream.addListener(statusListener);
twitterStream.filter(fq);
}
答案 1 :(得分:0)
您是否考虑过使用Twitter流媒体API?这允许您传递最多400个关键字,并获得包含其中任何单词的实时推文流。例如在twitter中为J看到这里:
twitter4j - access tweet information from Streaming API
替换
行 String keywords[] = {"France", "Germany"};
带
String keywords[] = {"sad","happy","joyful"};
你应该得到一些推文。