Comments (3)
This isn't too helpful to the issue but I am using a different module (Twit) and I believe that uses the v1 of the API and it is also disconnecting with the messages aborted
every 5 minutes without fail. This must be an issue with twitter.
from twitter-v2.
Thanks, Anthony. Somewhat reassuring that I am not the only one seeing this. As a follow-up:
- I updated my node version from 12 to 14 LTS. Since then, the stream does not end without error, but times out. This is not only odd, but from a data collection point of view even worse, because I wait for up to 30 seconds before reconnecting and probably miss tweets in the meantime. And it makes me wonder whether there is some low-level interaction problem between nodejs and twitter.
- I also created a very simple test script to check if the error is particular to twitter-v2, using needle instead of fetch as http client (as do most Twitter examples). Behavior is exactly the same. The script below for me closes reliably after ~5 min with "Stream unresponsive". (Would appreciate if someone else could confirm this.)
const needle = require('needle');
// Create 30 second timer to catch stream timeouts
// (Twitter sends 'keep alive' signal ~every 20 minutes)
let timer
refreshTimeout = function () {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
console.log(`${new Date()}: Stream unresponsive.`)
process.exit(0)
}, 30 * 1000)
}
// Send request to API filtered stream endpoint
// Ues TWITTER_BEARER_TOKEN from environment
const stream = needle.get('https://api.twitter.com/2/tweets/search/stream', {
headers: { "Authorization": `Bearer ${process.env.TWITTER_BEARER_TOKEN}` }
});
// Create listeners for stream events and log activity
stream
.on('data', function (data) {
refreshTimeout()
process.stdout.clearLine();
process.stdout.cursorTo(0);
try {
const json = JSON.parse(data)
if (json.data) {
process.stdout.write(`${new Date()} <- Time of last tweet.`)
} else {
process.stdout.write(`${new Date()} <- Message from Twitter: ${json}`)
}
} catch (error) {
process.stdout.write(`${new Date()} <- Keep alive signal received.`)
}
})
.on('err', function (error) {
console.log(`\n${new Date()}: Error (${error.message}).`)
})
.on('end', function () {
console.log(`\n${new Date()}: Stream ended.`)
});
``
from twitter-v2.
The issue also affects python (as tested with twitters own python example). I close this here since a solution will probably have to come from elsewhere.
from twitter-v2.
Related Issues (20)
- OAuth2 Application-based?
- [BUG] Twitter deep links don't linking to the intended page
- TypeError: url_1.URL is not a constructor HOT 1
- error code 410 error description unauthorized
- Error on adding multiple query parameters separated by space, in urlParams HOT 2
- Provide support for filtered streams HOT 3
- More streaming examples HOT 3
- User fields not returning any data HOT 2
- Lost in Documentation, how to get all tweets by user? HOT 1
- Export types/interfaces/etc from central index.ts file for consumer usage
- Sample codes for client.post(path, body, urlParams); HOT 2
- expansions missing and example HOT 1
- Unauthorized(401) when using tweets/search/recent HOT 8
- Iteration through paginated data HOT 2
- Handle .errors[] in streams
- Can't resolve 'crypto' in '/project/node_modules/twitter-v2/build' HOT 2
- Unauthorized when POST to Tweets endpoint HOT 8
- This doesn't work. Twitter API gives you 5 values. You only have variables for 4 of them. Get 'unauthorized' when trying to use values you suggest. HOT 1
- I can't reply to a specific tweet
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twitter-v2.