How To Make a Scary Russian Twitter Bot With Java

Using Twitter4J To Make Twitter API Requests

Martin Erlic
Mar 1, 2018 · 6 min read
Image for post
Image for post
In Mother Russia, bot think for you.

Apparently, I’m a Russian bot. This morning, at least, I was told to submit a phone number to Twitter to verify my identity because they claimed to have “detected suspicious activity” coming from my account.

In Tweet-speak, “suspicious activity” means simply to demonstrate a conservative political opinion. So I did what any sane software developer would do. I used a VPN to fabricate a fake phone number over Skype that I could use for SMS verification purposes…

Image for post
Image for post

Russian bots are clearly responsible for everything from nuclear power plant meltdowns to having you spill your coffee on your way to work in the morning. Obviously, then, these superpowers ought not be reserved for just the lucky few. In the spirit of fairness, I’ll show you how you too can make a Scary Russian Twitter Bot... in five easy steps to boot!

You don’t have to be a programmer to do this. Just follow my instructions closely and you should be able to get this going in no time.

Step 1 — Make a Twitter Application

The first step is to make a Twitter Application with the user account that you want to perform the API request with.

Click “Create New App” and fill in the fields. You can put whatever down you like. It really doesn’t matter.

Image for post
Image for post

Now that you have an “App”, go to the Keys and Access Tokens tab. Your App will have a Consumer Key and Consumer Secret. Take note of these.

Image for post
Image for post

Scroll down a bit and generate a new Access Token.

Image for post
Image for post

Take note of the Access Token and Access Token Secret.

Step 2— Create a Maven Project in IntelliJ

I like to use IntelliJ Community Edition for Java projects. Eclipse is a little outdated in my opinion, so make sure to download IntelliJ if you would like to follow along without a hitch.

The first thing we’ll want to do is create a Maven Project, which will allow us to include Twitter4J, the one dependency we need to get this running.

After opening IntelliJ, click File > New > Project… > Maven > Next:

Image for post
Image for post

Set the GroupId to com.blockchainmarty and the ArtifactId to TwitterAutoBot for consistency. They can be whatever you want but you’ll have to make sure they’re consistent throughout the program so just copy me for now.

Go to your pom.xml file and replace its contents with this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""




Nazdravlje! We have now set up Twitter4J with our project. Click Import Changes when the prompt pops up and wait for Maven to import the new dependency:

Image for post
Image for post

Step 3 — Prepare Tweets and Configure Twitter4J

In your resources directory, create a new File. Name it tweets.txt:

Image for post
Image for post

The way we’re going to set up this bot is to have it tweet line by line from this file until there are no more lines. The more unique your content, the less likely tweets will fail as a result of duplicate content detection. I suggest writing at least 100 unique tweets to get going. Of course, each line should be less than Twitter’s limit of 280 characters each.

Read this article for inspiration if you’re looking to get banned as quickly as possible. Here are a few examples:

I love Donald Trump #MAGA
Guns don't kill people. People kill people. #<3NRA
Any other conservative opinion.

In the same directory, create a new file called You will need to fill in the following information from Step 1 of this tutorial:


Now that we’re authenticated with our Twitter application, we can move ahead to the code.

Step 4 — The Source Code

Create a new Java Class in the src/main/java directory of your project. Make sure to name it TwitterAutoBot:

Image for post
Image for post

This file will contain all the code we need to blast out our deliciously offensive tweets. Paste the following, replacing whatever is already there:

import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

import java.nio.charset.Charset;

public class TwitterAutoBot {

Make sure to change the file path within the FileInputStream function to match the actual location of the tweets.txt file on your computer. This will definitely be different than what is shown above. Unless you’re using my computer, you Russian hacker! In which case, trakhat’ tebya!

Thread.sleep(x), where x is the number of minutes between tweets in milliseconds is probably the only thing you’ll want to customize. By default, I’ve set it to tweet once every 30 minutes. You can probably get away with once every minute if you like.

You’ll also want to go ahead and read the Twitter API Limits to familiarize yourself with how often you can tweet without getting bulldozed by your new sentient AI overlords. As we know, Twitter’s Trust & Safety Council is dark and full of errors…

Step 5 — Running The Program

From the top-right corner of the screen, click Edit Configurations…

Image for post
Image for post

Next, press the green plus sign, and select Application from the Add New Configuration menu:

Image for post
Image for post

Click Main class under the Configuration tab, then select TwitterAutoBot.

Image for post
Image for post

The last step is to click the green play button in the top-right corner of your screen:

Image for post
Image for post

If it worked, you’ll see something like the following in your debug terminal at the bottom of the screen:

Image for post
Image for post

There are obviously more sophisticated ways to do this, such as running the program as a cloud function that doesn’t require IntelliJ and your laptop to be always on, but that’s about all the time I’ve got for now. Please comment if you have any issues, and I’ll try my best to help out. Three cheers for prrrropaganda!

Image for post

Martin is Lead Project Manager at Selotec. You should follow him on Twitter.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store