Psychology, Entertainment, Work, and Technology
How To Make a Twitter-bot with Python for Your Company’s Social Media Management
How To Make a Twitter-bot with Python for Your Company’s Social Media Management

How To Make a Twitter-bot with Python for Your Company’s Social Media Management

TL;DR:

  1. Download Python if you haven’t already
  2. Download TwitterFollowBot and follow the instructions on GitHub
  3. Create new files on Python’s idle for different functions (e.g. Following, Retweeting, Liking, Unfollowing, Syncing)
  4. Run them as you please

(ProTip: Type pip install TwitterFollowBot on your Command Prompt (Windows) or Terminal (Mac OS)

I recently started working as a Social Media Manager. As such, Twitter bots – along with other social media automation tools – became an interest of mine. The idea was clear, I wanted a bot to like, follow, interact, and retweet within the parameters I assigned. The goal was to increase our company’s following and visibility on social media as a result of this.

However, the whole process of creating a bot seemed intimidating. I had an introductory course to programming behind me so seeing code didn’t make me zone out and start thinking about going on a beach vaca on a Greek island like it used to before. Nevertheless, this was a relatively new topic for me in programming languages that I wasn’t an expert with and if you’re anything like me, I can absolutely understand the frustration of getting started. I was on the fence of just paying for a Twitter bot but I felt like this is something I needed to do myself. This is how I did it:

Step 0. Google it

This is the first and the most obvious step. There’s a small chance you’re here because you already completed the first step. You’re gonna get some leads, some sales websites, some blog posts and what not. Some of them might offer a perfect solution but to be honest, it wasn’t that helpful for me, which is why I suggest taking a better step:

Step 1. Search on GitHub

Now we’re talking. There are dozens of open source bots for several social media platforms. Search “bot” with the social media channel you want (e.g. Twitter) and the language you want (e.g. Python). Python is reasonably simple and straight-forward, which is why I went for that instead of JavaScript.

Step 2: Install

Take your pick and follow the instructions. My choice was TwitterFollowBot. This might be easier said than done. The instructions are pretty clear but it’s possible you’ll run into some issues anyway. If you’re going with the same bot, you’re in luck. I’m going to share all my mistakes and issues I faced while getting it to work. You need to also get Python for using this bot (note: I spent two hours on Mac OS X trying to get the bot working on Python 3.6 before switching back to 2.7 – something to consider).

Download the bot by clicking on the Clone or Download button:

Screen Shot 2017-10-14 at 16.38.28

We’ll need this for the following part where we set up the bot but it’s good to have it there already. Once you’ve downloaded the zip and installed Python (along with pip if you don’t have it already), type

pip install TwitterFollowBot

on Command Prompt (Windows) or Terminal (Mac OS X). Congrats! You’ve installed it! Now to the part where we set it up:

Step 3. Set up

There’s a config.txt file in the TwitterFollowBot folder. You need to change some details in there to suit your own needs and run the bot. You get these details by creating a new Twitter app. ProTip: you need a Twitter account with a confirmed phone number for this.

Once you have that, find the keys in the Keys and Access Tokens section in Twitter Application Management. The OAuth keys can be generated below.

apps twitter.png

Copy-paste these to the config.txt file in your TwitterFollowBot folder. Almost there! Run the setup.py file to set up. Now you just need to create your own files for your own purposes.

Step 4. Create Functions

Create new files on Python’s idle (e.g. YourBotFollow.py) and write the code you want (all retrieved from the GitHub link). For example, to get your bot following other accounts, type:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow("phrase")

on the empty file and save. Click “Run Module” under “Run” or press F5. Voila! Your bot is running!

Apply to other functions and remember to sync every now and again with this piece of code:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.sync_follows()

Step 5. Done

Do what you want but remember Twitter’s guidelines. I myself am not going to claim no responsibility (and neither is anyone else) about what you use the bots for, so take care of yourself and hope you got it working!