[英]How to get more tweets by using twitter4j and parse to json?
I am using twitter4j to retrieve tweets from Twitter. 我正在使用twitter4j从Twitter检索推文。 As we know, we can only retrieve tweets less than 7 days.
众所周知,我们只能检索不到7天的推文。 Also we can only get 100 real time tweets.
另外,我们只能获得100条实时推文。 But I want to retrieve more than that.
但我想检索的不止于此。 After searching, I found that we can use
setSince
and setUntil
to get more than 100 tweets . 搜索之后,我发现我们可以使用
setSince
和setUntil
来获取100多个推文 。 But when I used setSince
and setUntil
, I still can only get real-time tweets. 但是当我使用
setSince
和setUntil
,我仍然只能获得实时推文。 Besides, I want to know how to parse my tweets to json format ? 此外,我想知道如何将我的推文解析为json格式 ?
Here's my code: 这是我的代码:
public static void main(String[] args) throws TwitterException, IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException
{
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("XXX")
.setOAuthConsumerSecret("XXX")
.setOAuthAccessToken("XXX")
.setOAuthAccessTokenSecret("XX");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
Query query = new Query("KEYWORD");
query.setCount(100);
query.setSince("2013-06-27");
query.setUntil("2013-07-02");
query.geoCode(new GeoLocation(XXX, XXX), 200, Query.KILOMETERS);
QueryResult result = twitter.search(query);
System.out.println(result);
}
If you are trying to get the 1000 most recent tweets in a search, for example, you should use query.setMaxId()
to the lowest # - 1 from your previous batch. 例如,如果您尝试在搜索中获取1000条最新的tweet,则应将
query.setMaxId()
用于前一批次中最低的#-1。 If you are trying to get new(er) tweets since your last query, you should use query.setSinceId()
to start from the value returned in result.getMaxId()
from the previous batch. 如果你想自上次查询来获取新的(ER)的鸣叫,你应该使用
query.setSinceId()
以从返回的值开始result.getMaxId()
一个批次。
Instead of a query you could use getUserTimeline(userid, page)
可以使用
getUserTimeline(userid, page)
代替查询
int tweetCount = 250;
long userId = 12312323;
twitter.getUserTimeline(userId, new Paging(1, tweetCount));
Documentation: http://twitter4j.org/oldjavadocs/3.0.0/twitter4j/api/TimelinesResources.html#getUserTimeline%28long,%20twitter4j.Paging%29 文档: http : //twitter4j.org/oldjavadocs/3.0.0/twitter4j/api/TimelinesResources.html#getUserTimeline%28long,%20twitter4j.Paging%29
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.