skip to Main Content

Hello i want to create a bot who will automatically send a message to the men who follow you


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)
} 

but when i start the app i got this error

      throw er; // Unhandled 'error' event
      ^

Error: Bad Twitter streaming request: 404
    at Object.exports.makeTwitError (C:UsersguillDesktopProgrammationwelcomemessage-V1.0.0node_modulestwitlibhelpers.js:74:13)
    at Request.<anonymous> (C:UsersguillDesktopProgrammationwelcomemessage-V1.0.0node_modulestwitlibstreaming-api-connection.js:96:29)
    at Request.emit (events.js:327:22)
    at IncomingMessage.<anonymous> (C:UsersguillDesktopProgrammationwelcomemessage-V1.0.0node_modulesrequestrequest.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.<anonymous> (C:UsersguillDesktopProgrammationwelcomemessage-V1.0.0node_modulestwitlibstreaming-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 can help me ?

2

Answers


  1. i dont think that T.stream(‘user’); is still working now, i have a mission now to built a bot for a client and i had the same problem,

    Try to use T.stream(‘statuses/filter’), or T.stream(‘sample’)

    Login or Signup to reply.
  2. Replace:

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

    With

    var stream = T.stream('statuses/filter', { track: '@<your_twitter_username>' });
    

    Thanks to Asaolu Elijah Response on github issue

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search