Howdy! Thanks for coming and enjoy your stay! Take a look at the sitemap and don't forget to chirp!

Twitter Robot in PHP: Twibots Draft

January 25th, 2010

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

Create Your Own Twitter Robot in PHP

Create Your Own Twitter Robot in PHP

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 bit.ly 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 https://twitter.com/…
# 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!

Related posts:

  1. Create Your Own Automated Twitter Robot in PHP
  2. Robots Are Doing Better Than Humans on Twitter
  3. A Robot Playing Ping Pong!
  4. Automated Twitter Bot in PHP: Remote Control
  5. Twitter API: Moving From Basic Auth to OAuth

11 Responses to “Twitter Robot in PHP: Twibots Draft”

  1. I’ve waiting so long and it’s happens! Holy gods! :)

    • kovshenin (@kovshenin)

      You’re welcome Alex ;) Let me know how it goes.

  2. Nice, but where is class.twitter.php? It’s not included in the zip.

    • kovshenin (@kovshenin)

      Perhaps I forgot to remove the require line. The robot shouldn’t use class.twitter.php because it’s using the OAuth version.

  3. Joe

    Got this error :

    Warning: MagpieRSS: fetch_rss called without a url bla bla bla/rss_fetch.inc on line 238
    Warning: in_array() [function.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

    Thanks

    • kovshenin (@kovshenin)

      Joe, the first warning says it all, fetch_rss called without a url. Did you provide it with a valid Atom/RSS url?

      • Joe

        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://bit.ly/abcde is missing..

        Is it because the url it too long so bit.ly doesn’t short it?

        Thanks

  4. Jason Tucker (@jasontucker)

    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?

    • kovshenin (@kovshenin)

      Jason, which version of PHP are you running?

Including pingbacks & trackbacks

  1. Tweets that mention Twitter Robot in PHP: Twibots Draft -- Topsy.com linked here on January 26, 2010 at 10:26 am
  2. uberVU - social comments linked here on January 26, 2010 at 2:34 pm