Reputation: 3447
I am currently trying to stream two tracks at the same time on the same connection, the problem I have is that a new connection is opened for the second stream in which Twitter rejects with error code 7, which is Twitter throwing off the oldest connection to make way for the newest, is there anything I can do programatically to prevent this?
This is the code I am using
var request = oa.get("https://stream.twitter.com/1.1/statuses/filter.json?track=tweet1", access_token, access_token_secret );
request.addListener('response', function (response) {
response.setEncoding('utf8');
response.addListener('data', function (chunk) {
var theTweets = JSON.parse(chunk);
console.log(theTweets);
MongoClient.connect("mongodb://localhost:27017/db", function(error, database) {
var collection = database.collection('coll');
collection.insert(theTweets, function(err, result) {});
});
});
response.addListener('end', function () {
console.log('--- END ---');
});
});
var requestTweet2 = oa.get("https://stream.twitter.com/1.1/statuses/filter.json?track=tweet2", access_token, access_token_secret );
requestTweet2.addListener('response', function (response) {
response.setEncoding('utf8');
response.addListener('data', function (chunk) {
var theTweets = JSON.parse(chunk);
MongoClient.connect("mongodb://localhost:27017/db", function(error, database) {
var collection = database.collection('coll');
collection.insert(theTweets, function(err, result) {});
});
});
response.addListener('end', function () {
console.log('--- END ---');
});
});
requestTweet2.end();
request.end();
Upvotes: 0
Views: 767
Reputation: 11
The Twitter public stream will only accept one connection per IP address. You can find this documented here.
Each account may create only one standing connection to the public endpoints, and connecting to a public stream more than once with the same account credentials will cause the oldest connection to be disconnected.
As an alternative you might use the user stream, which limits the incoming tweets to the account of the authenticated user.
Upvotes: 1