如何在 Twitter getmentiontime 行中使用时间/计数
我可以获得用户的时间线,但现在 我想获得最近 30 分钟的提及时间线。
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_SECRET)
.setOAuthAccessToken(ACCESS_TOKEN)
.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
User user = twitter.verifyCredentials();
List<Status> statuses = twitter.getMentionsTimeline();
System.out.println("Showing @" + user.getScreenName() + "'s mentions.");
请建议我需要进行哪些更改。
最佳答案
您可以使用Paging
对象的 max_id
参数可在您正在处理的时间轴中后退:
max_id
Returns results with an ID less than (that is, older than) or equal to the specified ID.
例如,选择要获取的合理数量的状态(最多一次提及 200 个),例如:
Paging paging = new Paging();
paging.count(100);
获取提及:
final List<Status> statuses = twitter.getMentions(paging);
然后记录最早的Status
的id
,然后使用该id
作为该状态的max_id
属性下一次通话:
paging.maxId(id - 1); // subtract one to make max_id exclusive
final List<Status> statuses = twitter.getMentions(paging);
依此类推,直到达到三十分钟的阈值。
有关详细信息,请参阅 Twitter 的文档 Working with Timelines 。此外,请注意,此 API 调用可能会达到速率限制。
关于java - Twitter getMentionTimeLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18712607/