twitter4j搜索

5cg8jx4n  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(243)

我试着在twitter上搜索。我使用twitter4j库。我的问题是,我想搜索hashtags,它也包含我搜索的指定单词。例如:如果我搜索#hello,我希望我的结果是:#hello#helloworld#hellothere等
这是我在searchview上的代码:

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
                                        {
                                            @Override
                                            public boolean onQueryTextSubmit(String query1)
                                            {

                                                return false;
                                            }

                                            @Override
                                            public boolean onQueryTextChange(String newText)
                                            {
                                                if(!newText.startsWith("#"))
                                                {
                                                    newText = "#" + newText;
                                                }

                                                try {

                                                    Query query = new Query(newText);
                                                    query.setCount(100);

                                                    QueryResult result = twitter.search(query);

                                                    int c=1;

                                                    for(Status status: result.getTweets())
                                                    {
                                                        System.out.println("\nFor round:" + c+ "\nThe status is:"+ status.getText());
                                                        System.out.println("\n--------------");
                                                        System.out.println("\n-------Here are the hashtags for this post-------");

                                                        c++;
                                                    }
                                                } catch (TwitterException e) {
                                                    e.printStackTrace();
                                                }

但当我在搜索栏上键入hello时,它只会在我的控制台上显示(我知道我必须在屏幕上显示它们)带有“hello”的tweet。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题