我使用Twitter4J搜索推文。我使用了Query类。我创建了自己的推文,用我想要的短语来搜索试试。但是当我搜索它时似乎没有看到我的推文。那么如何确定我是否可以搜索推文呢?
我的代码是:
Twitter twitter = new TwitterFactory(getConfig().build()).getInstance();
Query query = new Query(URLEncoder.encode("#MatthewPogi"));
QueryResult qr = twitter.search(query);
List<Status> statuses = qr.getTweets();
for(Status status: statuses) {
System.out.println(status.getId() + " " + status.getText() + " " + status.getSource());
答案 0 :(得分:1)
试试这个:
*Query query = new Query("#MatthewPogi");
QueryResult result;
do {
result = twitter.search(query);
List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
Date createdAt = tweet.getCreatedAt();
System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getUser().getCreatedAt() + " - " +tweet.getText() + " - " +tweet.getUser().getLocation());
}
} while ((query = result.nextQuery()) != null);*
答案 1 :(得分:0)
Query query = new Query("ekkada");
QueryResult result;
do {
result = twitter.search(query);
List<Status> tweets = result.getTweets();
int i = 0;
for (Status tweet : tweets) {
fw.write("#" + (i++) + " " + tweet.getCreatedAt() + " @" + tweet.getUser().getScreenName() + " - " + tweet.getText());
fw.write("\n");
}
} while ((query = result.nextQuery()) != null);