Twitter Bot Examples

Return to demos index page

Share on Facebook Tweet about this on Twitter Share on Google+ Share on StumbleUpon Share on LinkedIn Share on Reddit pinterest Email this to someone

twitterbotlogo

Last updated: 2018-02-25

Introduction

Seeing all the news about how Twitter Bots had been causing so much trouble in our last election, and indeed right up until today, got me wondering why on Earth something so malicious could be allowed to exist.

As it turns out, like many things that are used for malicious purposes, the Twitter Bot itself is a really awesome concept that is not intended for evil or stupidity. They have wide ranging uses for many different types of business and promotion. It just so happens that they can just as easily be put to use spamming the crap out of people, or flooding our news cycles with bullshit.

It got me thinking and doing research. I wanted to know how these things work, and what actual purpose could they serve. The best example of a spiffy usage for such a tool was to send out daily content to followers automatically. Since I already had in app in place that does exactly that, and I already had the entire back end built, I simply utilized the ability to call up a single record and Tweet it. The end result is the Quote of the Day Twitter Bot.

It also got me thinking that it was time to jot down my thoughts on this project as a way of sorta blogging what I'm doing.

What is a Twitter Bot (or Twitterbot)?

Short answer: A bunch of stuff that automatically posts stuff to Twitter. They can also read information from other feeds.

Long answer: A Twitter Bot consists of a number of different parts. And there are many different ways to go about building one. You can use PHP, JavaScript, PERL, or any number of other languages to do all the actual work. Anything that can talk to the Twitter API will do the job.

For those that don't know, an API is an Application Protocol Interface. It's basically a set of prewritten code that allows developers to access predefined services and make use of them.

Twitter Bots all start out the same way. You create a Twitter account just like any other. You then create a Twitter Application, telling Twitter you would like to access the account from elsewhere.

That is about the only common element for all Twitter Bots. What happens after that is entirely up to the developer.

The rest of a Twitter Bot consists of the following:

  • Code that generates content. PHP, JavaScript, etc.
  • Code that creates the interface to talk to Twitter
  • A Cron job on your server to automatically execute your script at a given interval. Once a day, or once every half hour, for example.
twitterbotlogo

In my case, I use PHP on the server. There are tons of examples out there. I went with this one. That is code that some other person wrote that takes care of the whole "talk to Twitter" thing. That's one of the great things about being a developer nowadays. If you need to do something, someone out there has done it, solved it, and provided a solution. But I digress...

So now I have a means to send my content to Twitter. I used the Quote of the Day app because I had already written that entire thing. So I have a database with all the content, and a script to pull it. I added that to the code, and after some minor troubleshooting, got the "remote posting" thing working.

The last step in the process is to go to the server and set up a Cron job. This is something that is common to all systems. Everyone loves being able to automate things that are constantly repeated. That's the last step in the process. So now, once a day, around 12:30PM or so, it fires off a new quote.

That one is finished, but I have other ideas

The Twitter Bot described here only does one thing. Tweet once a day. That is probably the simplest usage for one of these things. I've already written 3 others that do the same thing with different content - the attached feed is my sandbox for testing these things. I'm going to continue to use that account to create some new bots and test them there. If you want to follow the account, go right ahead. You may see some amusing nonsense while I'm testing stuff.

Anyway... Twitter Bots can also do much, much more. The can read live feeds, respond to to Follow requests, send messages to users, etc... This is the reason for the sandbox account. I want to really explore how these things can be effective.

In the sandbox, I have a few working bots that trigger randomly. So any of these will pop up when the Cron job fires:

  • Year Progress. Shows how much of the year has expired.
  • Picture of the day. One of like 100 random images.
  • GIF of the day. One of a collection of animated GIFs. I don't even know how many are there.

This is the live feed from the @DPExperimentBot timeline so you can see what they look like. Feel free to follow. Let me know if you think any of them are good enough to stand alone.


bottom corner