繁体   English   中英

获取最新的tweet并将其存储在twitter4j中

[英]getting latest tweet and storing it twitter4j

我是twitter4j和处理的新手。

我想从单词列表中获取最新搜索到的单词。 我希望将其存储在要查询的变量中。 所以:

PossibleWords[] ={"sad","happy","joyful"}

然后,我想要一个字符串变量searchString来保存最新的推文推文,其中包含来自数组的单词。 例如,如果悲伤只是在今天发布,我想得到那条推文。 因此,我需要测试数组中的任何单词是否在最新的tweeted单词中。

从概念上讲,我理解这一点,但是有人对此编程有任何建议吗? 这在使用twitter4j处理3

您应该使用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);
    }

您是否考虑过使用Twitter流API? 这样一来,您最多可以传递400个关键字,并获得包含其中任何单词的实时tweet流。 例如,在Twitter上查看J:

twitter4j-从流API访问推信息

更换线

 String keywords[] = {"France", "Germany"};

 String keywords[] = {"sad","happy","joyful"};

您应该会收到一系列推文。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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