twit icon indicating copy to clipboard operation
twit copied to clipboard

Error 404 with the var stream

Open PurpleRain12 opened this issue 5 years ago • 3 comments

hello i want to create a script who send a welcome message when someone follow me

so i create a test :

`console.log('Started The bot');

var Twit = require('twit');

var config = require('./config'); var T = new Twit(config);

var stream = T.stream('user');

stream.on('follow', followedMessage);

function followedMessage(eventMsg) { console.log('+1 follow'); var fs = require('fs'); var json = JSON.parse(eventMsg); fs.writeFile("tweet.json", json) } `

and i got an error :

`events.js:292 throw er; // Unhandled 'error' event ^

Error: Bad Twitter streaming request: 404 at Object.exports.makeTwitError (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\helpers.js:74:13) at Request. (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\streaming-api-connection.js:96:29) at Request.emit (events.js:327:22) at IncomingMessage. (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\request\request.js:1076:12) at Object.onceWrapper (events.js:421:28) at IncomingMessage.emit (events.js:327:22) at endReadableNT (_stream_readable.js:1221:12) at processTicksAndRejections (internal/process/task_queues.js:84:21) Emitted 'error' event on StreamingAPIConnection instance at: at Request. (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\streaming-api-connection.js:99:14) at Request.emit (events.js:327:22) [... lines matching original stack trace ...] at processTicksAndRejections (internal/process/task_queues.js:84:21) { code: null, allErrors: [], twitterReply: '', statusCode: 404 }`

someone for helping me ?

PurpleRain12 avatar Aug 20 '20 17:08 PurpleRain12

The User Stream API was retired and removed in 2018, so this unfortunately no longer works. You need to use the Account Activity API instead, and the twit library does not support that. You could take a look here to see if it might help?

https://github.com/ttezel/twit/issues/445

You can also use Twitter's autohook library. There's a full tutorial here.

andypiper avatar Aug 21 '20 16:08 andypiper

@andypiper So there is no way to use twit to respond to follow events?

cparello avatar Aug 27 '20 21:08 cparello

I am not aware of a way to use twit directly with the Account Activity API, you would have to check with the maintainers - that’s why I suggested autohook or an alternative. There’s are no “follow events” on user streams because user streams do not exist any more.

andypiper avatar Aug 27 '20 21:08 andypiper