https://github.com/dmanjunath/rate-limiter
Twitter API for node.js with rate limiter
https://github.com/dmanjunath/rate-limiter
Last synced: 11 months ago
JSON representation
Twitter API for node.js with rate limiter
- Host: GitHub
- URL: https://github.com/dmanjunath/rate-limiter
- Owner: dmanjunath
- Created: 2013-07-20T20:41:44.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-06-20T02:52:02.000Z (almost 12 years ago)
- Last Synced: 2025-06-16T13:12:29.059Z (12 months ago)
- Language: JavaScript
- Size: 2.33 MB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
rate-limiter
====================
## Description
This module helps manage your requests to the Twitter API so you don't get rate limited. If you use
the module to make requests, it will automatically queue your requests and if you are in danger of exceeding Twitter's
API limits, it will store them and execute them after the time window has passed. No more worrying about rate limiting.
## Instructions
npm install twitter_rate_limiter
## Setup
Create a file called config.json with your twitter credentials in the format
```javascript
{
"twitter":{
"consumerKey": "...",
"consumerSecret": "...",
"token": "...",
"tokenSecret": "..."
}
}
```
You could hardcode it into the file but that wouldn't be advisable.
##Usage
In your file, import the config.json file
Import the rate_limit.js file
var RateLimiter = require('../rate_limit.js');
Instantiate a new RateLimit object.
```javascript
var getfriends = new RateLimiter(2, 5000);
```
The two arguments are the requests in the time window in the form(requests, time window). Usually the time window is 900000 ms for 15 minutes. The request number varies by function call
Create a function for the twitter call you want to make. This example shows the GET friends request
```javascript
var callGetFriends = function(username, callback) {
var url = 'https://api.twitter.com/1.1/friends/ids.json?cursor=-1&screen_name='+username+'&count=5000';
console.log(url);
request.get({url: url, oauth: oauth, json: true}, function(error, res, body) {
callback(body);
})
}
```
The function calling this would look like
```javascript
getfriends.callWithLimit(callGetFriends, ["user", function(data){
console.log(data);
"...insert processing here"
}]);
```