[英]node-ntwitter and twitter API Limites
Question related to the API limits, It might be something I'm just missing, not sure though: 与API限制有关的问题,可能是我所缺少的,但不确定:
If I do this: 如果我这样做:
twit.showUser(ids, function(error, response) {
console.log(response)
}
Where {ids} is an Array, with length < 100, all is well. 其中{ids}是一个数组,长度小于100,一切都很好。
When I do the same and IDs is > 100, it fails. 当我执行相同的操作并且ID> 100时,它将失败。
This is based on: https://dev.twitter.com/docs/api/1.1/get/users/lookup 这基于: https : //dev.twitter.com/docs/api/1.1/get/users/lookup
And specifically: 特别是:
for up to 100 users per request
每个请求最多100个用户
Is this somehow managed in ntwitter module or do I need to manage this outside? 这是在ntwitter模块中以某种方式管理还是我需要在外部进行管理? if so, any recommendation on how to manage that?
如果是这样,关于如何管理它的任何建议?
Or, outside of the node-ntwitter module, how would you recommend solving this in a clean way if I want to send back a composite json of all responses from showUser() ? 或者,在node-ntwitter模块之外,如果我想从showUser()返回所有响应的复合json,那么您将如何建议以一种干净的方式解决此问题?
for up to 100 users per request
每个请求最多100个用户
means you can only request 100 ids at a time. 表示您一次只能请求100个ID。 You can run a for-loop with an increase of 100:
您可以增加100来运行一个for循环:
for(var i = 0; i < ids.length; i + 100) {
requestIds = ids.slice(i, i+99)
twit.showUser(requestIds, function(error, response) {
console.log(response)
}
}
(untested) (未试)
As it's node.js, you might want to have it asynchronous. 由于它是node.js,因此您可能希望使其异步。 Check out forEachLimit and forEachSeries .
签出forEachLimit和forEachSeries 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.