DEV Community

How I Created Two Twitter Bots

Ben Greenberg on November 06, 2017

With the news cycle every day never failing to mention the insidious Twitter bots that caused havoc during the 2016 election cycle, I became curi...
Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
bengreenberg profile image
Ben Greenberg

Hey Dulan! There is no such thing as a dumb question first of all. Secondly, the touch command is just to create a new file. In what ever way you create new files in your environment go ahead and do so. Perhaps you just need to create a new file from your editor (i.e. Atom, VS Code, etc.)? Ben

Collapse
 
hbibzdeploy profile image
Muhammad Habib Jawady

touch is a Unix command available on Linux terminals and I think also powershell to create new files ... No worries, the usual file creation via a text editor will do

Collapse
 
peter profile image
Peter Kim Frank

Great write-up, Ben! Always excited when I get a notification that you've published a new article.

Coding for Liberal Arts Programmers

Subscribed.

What's the typical delay on your "Remember Us All" bot? Meaning, how long does it take for your bot to "reply" after the initial tweet? I've definitely noticed the mad-dash from other accounts and would imagine it's something of an arms-race to be one of the first accounts to reply. Presumably Twitter weighs the reply speed against things like "Verified" and "# of followers" when they sort the replies to a tweet. Would be interested in the various techniques to clamp down that delay.

Thanks again for a great post.

Collapse
 
bengreenberg profile image
Ben Greenberg

Thanks Peter!

That's a good question, which I am not sure I have a good answer for. I wonder if anyone else knows how that "arms race" is calculated on Twitter's end. My bot is set to follow his account and post a reply as soon as it detects a tweet, but what "soon" means is not clear to me either. Something to definitely look into.

Collapse
 
bengreenberg profile image
Ben Greenberg

Just an update I think you might find interesting Peter. My "Remember Us All" bot ended up getting suspended twice. Whereas my job retweeting bot is still going strong. Both are essentially doing similar actions on Twitter with similar intervals between tweets. The only difference primarily is the content. It looks like Twitter has a low threshold for content that falls in this category, which is interesting to me because the platform definitely doesn't feel like a neutral zone! Anyways, after the second suspension, it was becoming too much work to keep on appealing it and the bot is currently "sleeping" for the time being.

Thread Thread
 
peter profile image
Peter Kim Frank

Very interesting. I would think the "First replies to Trump" arena is the most competitive and tightly watched area for bots on the entire site. So it's not totally surprising to me that the "Remember Us All" bot got suspended, especially given the subject matter and likelihood that people are reporting it.

Thanks for circling back here; I've been curious about this type of stuff for a long time.

Collapse
 
colliepixels profile image
colliepixels

Thanks for posting such a clear & easy to follow tutorial.
I have a question.
I keep getting the error "Error: Twit config must include consumer_secret when using user auth." when I run twitterBot.js in terminal. I have run the export commands with the keys. What am I doing wrong?
Is there another way I can add the keys?
Thanks.

Collapse
 
srivinprabhash profile image
Srivin Prabhash

I tried this. But when I ran node bot.js it gives me this TypeError

TypeError: Cannot read property 'id_str' of undefined

I don't have any knowledge on node though -_- .. Any idea to fix this ?

Collapse
 
bengreenberg profile image
Ben Greenberg

Hey Srivin,

It sounds like you are not getting back from the Twitter API what you are expecting to get back. The first step to debugging this would be to check what data is, perhaps by putting it in a console.log and then working backwards step-by-step to see where in the chain of events you are not either a) sending the right credentials to Twitter or b) not getting back the right data.

Good luck!

Ben

Collapse
 
hayanisaid1995 profile image
SaadHayani@

Thank you So Mush Ben absolutely useful Article

Collapse
 
bayflights profile image
BayAreaFlightDeals

Hey Ben, thanks so much for the article. Wondering how it filters the retweets to make sure that it isnt retweeting the same posts? Does twitter do that part?