nisrulz / twitterbot-nodejs

[Bot] A twitter bot made using nodejs which can post tweets, retweet other tweets and possibly fav tweets
http://nisrulz.github.io/twitterbot-nodejs
Apache License 2.0
145 stars 73 forks source link

This no longer works. #2

Open blackhanddev opened 5 years ago

blackhanddev commented 5 years ago

It stopped working suddenly.

nisrulz commented 5 years ago

Can you provide more details, stacktrace or what is not working?

This repository only has the code for it. You still need to deploy the twitterbot using your own twitter application api. There are other twitter bots that are live and they are completely functional.

wilburforce83 commented 5 years ago

@blackhanddev twitter have changed API I believe, I am getting 404 error too:

$ node bot.js
I wish I started trading earlier than I did but I thankGod for my experience and
 journey. Start trading today… https://t.co/tm63bW9HjM
Happiness is growth and development I’m excited for what’s to come and I’ll cont
inue to share my journey hoping to… https://t.co/1QvjgSS6Ns

DM for safe secure and guarantee investment with a…
RT @FraudForex: we can confirm that Konto fx is a SCAM #uprofx #konto_fx #invest
mentscam #BitcoinTwitter #bitcoin #cryptocurrency #binaryop…
#enterpreneur #stocks #stockmarkets #bitcoin #enterprenureship #binaryoptions ht
tps://t.co/sfZ0tB8SqR
Market movers for tomorrow!

#ECB #forex #binaryoptions #futures #nadex #forextrader #forexlifestyle #daytrad
er… https://t.co/Bcn6vYZQBe
RT @jimmytradesbtc: I’m still trading #binaryoptions and #Forex ��  All grown.
 Make sure you’re trading with the right and proper signal se…
Never give up be so determined in whatever you do! Investors all over the world
are making earnings. You can cruise… https://t.co/LBJyhuq0Ke
Never give up be so determined in whatever you do! Investors all over the world
are making earnings. You can cruise… https://t.co/wUZDXzBBPw
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: Bad Twitter streaming request: 404
    at Object.exports.makeTwitError (C:\Users\User\Documents\Projects\twitterbot
-nodejs\node_modules\twit\lib\helpers.js:74:13)
    at Request.<anonymous> (C:\Users\User\Documents\Projects\twitterbot-nodejs\n
ode_modules\twit\lib\streaming-api-connection.js:96:29)
    at Request.emit (events.js:194:15)
    at IncomingMessage.<anonymous> (C:\Users\User\Documents\Projects\twitterbot-
nodejs\node_modules\request\request.js:1083:12)
    at Object.onceWrapper (events.js:277:13)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Request.<anonymous> (C:\Users\User\Documents\Projects\twitterbot-nodejs\n
ode_modules\twit\lib\streaming-api-connection.js:99:14)
    at Request.emit (events.js:194:15)
    [... lines matching original stack trace ...]
    at process._tickCallback (internal/process/next_tick.js:63:19)

User@DESKTOP-KSHARRN MINGW64 ~/Documents/Projects/twitterbot-nodejs (master)
$
wilburforce83 commented 5 years ago

It is the stream call that is causing it, If you just want to retweet comment out the parts which are replying to followers and mentions.

I have forked this repo to try and get it working again. Everyone online is basically saying the tweet back a follower type thing is dead after they pulled stream.on() sorting out webhooks for someone messing about on raspberry pi or something is too much of a pain in the ass.

I am going to build a workaround which stores followers as an array then compares for changes, filters the new usernames and sends them tweet. It is not perfect, frankly is quite hacky, but it does mean we can still have low level bots for sending out automated replies to new followers :)

Something like:

   T.get('followers/list', function (error, data) {

    if (!error) {

      if (followers === undefined) {
        followers = reportBouncer(data.users.map(data => data.screen_name));
        welcomeTweets = followers;
      }

      if (followers != []) {
        welcomeTweets = reportBouncer(data.users.map(data => data.screen_name)).filter(function (id) {
          return !followers.includes(id);
        });
        // update followers after getting new ids
        followers = reportBouncer(data.users.map(data => data.screen_name));
      }

      console.log(welcomeTweets);
    } else {
      console.log('Error with follower grab', error);
    }

  })

    function reportBouncer(arr) {
        return arr.filter(Boolean);
    };

with a T.post() inside a for each loop to send a tweet to each new follower per cycle.

nisrulz commented 5 years ago

I built this project year back as a sort of side project. I haven't looked into upgrading it or improving it. Honestly, I have lost track on what API changes Twitter has gone through in this time. As mentioned in the Readme, the bot I built with this is still live as of today (https://twitter.com/gdgndbot). Since it has worked for me, I had no need to come back and make more changes. However, I am happy to know it caught your interest. Feel free to submit a PR if you would like to contribute it back to the project

About your issue at hand and solution for it: Because Twitter restricts the streaming API as well as might block your bot if you were to send replies via a for loop mechanism.

The way I would solve this is to accumulate all the followers but send them response randomly throughout the day instead of via for loop. Think of it as a backpressure based stream of events. This allows the bot to not be marked for abuse of API and at the same time act more natural. No one responds right away ;)

wilburforce83 commented 5 years ago

@nisrulz I think you'll find only the retweet part of the bot will be working. 100% stream.on() returns 404 and has done for a while.

For anyone interested my fork has a refactored solution for stream events which don't require the annoying new webhook system.

It's quite different, but would be happy to clean the code and do a PR :)

jappy1961 commented 4 years ago

wilburforce83

change

var stream = T.stream('user')

to

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