Twitter Robot in PHP: Twibots Draft

As I promised quite some time ago, I’m putting out a draft of the Twitter Robot I wrote. Make sure you read Create Your Own Automated Twitter Robot in PHP before going on. The current functionality is as follows:

  • Tweets around the clock
  • Tweets from RSS feeds, supporting prefix and postfix text (for adding hashtags)
  • Retweet via the Twitter Search API and build conversation lists
  • Shoot random sentences at users who mention you, thank them for retweets
  • Control your robot via your own Twitter account by sending him direct messages
  • All this is Twitter OAuth powered, no password required
  • Such robots are called Twibots

Now, before downloading the code, I have to warn you that it’s completely unorganized. The code is horrible, comments are awkward, the database being used is SQLite (just for the fun of it) and it’s very very glitchy. Be prepared for Twitter suspending your account for ‘strange activity’ and use this at your own risk, don’t run here blaming me for that ;) I also suggest you’d contact Twitter to get your IP addresses and Twitter account white-listed before you start, especially if you plan to tweet very often (which I wouldn’t recommend). Use this at your own risk, and please keep my copyrights and preferably the OAuth application IDs.

Download: here (version 0.1)

Operation Instructions.. To say the truth it’s pretty tough, no web interface, not buttons, no config files. There are a bunch of files there, some of them useless. There’s the Snoopy class for reading and parsing RSS, there’s the Twitter OAuth class, and two core php files – cron.php and oauth.php. Open up cron.php, there are some comments and examples there. Make sure you get your own API key and secret. Also make sure you get a connection with the twibots.sqlite database which has a couple of empty tables. Those will be used for tokens and dump data for unrepeated tweets.

Once you’re done configuring, use the command-line php in order to make it work. It goes something like this:

# php cron.php oauth register
# Please browse to
# php cron.php oauth validate 123465
# Authentication successful, greetings @ev ;)

# php cron.php random
# tweeting a random RSS feed ...

# php cron.php reply
# sending replies...

# php cron.php dm
# reading direct messages

# php cron.php retweet
# retweeting...

You’ll have to put that in your crontab file and launch by schedule. Don’t run them too often though, as Twitter doesn’t like flooding, especially from newly created accounts. Any questions or suggestions are welcome in the comments below, but please, don’t tell me the code is horrible, I know it is, and I wouldn’t have posted it if you didn’t ask ;) Cheers!

14 thoughts on “Twitter Robot in PHP: Twibots Draft

  1. Tweets that mention Twitter Robot in PHP: Twibots Draft --

  2. uberVU - social comments

  3. Got this error :

    Warning: MagpieRSS: fetch_rss called without a url bla bla bla/ on line 238
    Warning: in_array() []: Wrong datatype for second argument bla bla /cron.php on line 292
    Warning: Invalid argument supplied for foreach() in /home/xxx/cron.php on line 297


    • Hi, It's all doing fine now.. I can get it to work. But it's strange that when I'm testing it to fetch rss from amazon, it does fetch the rss and tweet it but with no url in the tweet the _hxxp:// is missing..

      Is it because the url it too long so doesn't short it?


  4. I’m getting this error:
    Parse error: syntax error, unexpected ‘,’, expecting ‘(‘ in cron.php one line 33

    line 33 is: $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    Any ideas?

  5. Hi Konstantin,

    This is an excellent script!

    I wonder if I set the crontab to every 15 minutes will it update my status with random tweet taken from the RSS of my website. My blog isn't updated every day and there are not many RSS entries.

    I want to know if will it randomly repeat the RSS?



    Warning: MagpieRSS: fetch_rss called without a url in /home/best/public_html/tw/ on line 238

    Warning: Invalid argument supplied for foreach() in /home/best/public_html/tw/cron.php on line 300

Comments are closed.