我目前正在尝试在同一连接上同时流式传输两个轨道,我遇到的问题是为第二个流打开了一个新连接,其中 Twitter 拒绝并出现错误代码 7,这是 Twitter 放弃了最旧的连接为最新的让路,我能以编程方式做些什么来防止这种情况发生吗?
这是我正在使用的代码
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();