如何检索哈希标记的最新推文?我使用twitter4j 3和处理2
到目前为止,我只能检索一定数量的推文,但我想检索最新的#willsmith哈希标签推文:
继承我的代码:
void connectTwitter() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("XXXXXXX");
cb.setOAuthConsumerSecret("XXXXXXX");
cb.setOAuthAccessToken("XXXXXXX");
cb.setOAuthAccessTokenSecret("XXXXXX");
twitterFactory = new TwitterFactory(cb.build());
twitter = twitterFactory.getInstance();
println("connected");
}
// Get your tweets
void getTimeline() {
try {
statuses = twitter.getHomeTimeline();
}
catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
for (Status status:statuses) {
println(status.getUser().getName() + ": " + status.getText());
}
}
// Search for tweets
void getSearchTweets() {
try {
Query query = new Query("#willsmith");
query.setCount(100);
QueryResult result = twitter.search(query);
for (Status status : result.getTweets()) {
println("@" + status.getUser().getScreenName() + ":" + status.getText());
}
}
catch (TwitterException e) {
println("Search tweets: " + e);
}
}
有什么建议吗?
答案 0 :(得分:0)
我没试过,但这可能就是你要找的东西:
query.setResultType(Query.RECENT);
query.setCount(10);