My favorites | Sign in
Project Logo
                
Code license: MIT License
Labels: php, bot, twitter, search
Show all Featured downloads:
phptwitterbot-1.0.0.zip
Feeds:

PHP Twitter Bot

What's that?

A simple Twitter Bot written in PHP5, allowing to search and retweet things.

Quick example

<?php
$bot = new TwitterBot('myusername', 'mypassw0rd');
$bot->searchAndRetweet('rotfl', 'RT @%s: %s');

This code will search for the term rotfl in the twitter timeline, extract the first matching result and retweet it using the RT @%s: %s format, using the credentials provided in the class constructor.

Of course, this script is intended to be run regularly, eg. using CRON.

Oh, and because someone asked, you have of course to create a dedicated Twitter account for your bot. The myusername and mypassw0rd values are the credentials of your bot account.

Real World Examples

Here and here (hem, I'm sorry, really).

Miscelaneous

The bot can follow the retweeted twit author using the third optional Boolean parameter of the searchAndRetweet() method:

<?php
$bot = new TwitterBot('myusername', 'mypassw0rd');
$bot->searchAndRetweet('rotfl', 'RT @%s: %s', true);

The bot can also check if he has followers, and then follow them as well:

<?php
$bot = new TwitterBot('myusername', 'mypassw0rd');
$bot->followFollowers();

By default, the class won't write anything to the console output (no cronmail), but you can activate debugging when instantiating the bot:

<?php
$bot = new TwitterBot('myusername', 'mypassw0rd', true);

Full Documentation

Read the phpDoc, it's really simple.

Installation

Just checkout the SVN repository from a command prompt:

$ svn checkout http://phptwitterbot.googlecode.com/svn/tags/1.0.0 phptwitterbot

Then just require the TwitterBot.class.php file:

<?php
require_once 'phptwitterbot/TwitterBot.class.php';
$bot = new TwitterBot('myusername', 'mypassw0rd');

More to come?

Honnestly, I don't know. Maybe a TwitterBotsFarm class? ;-)

License

This code is released under the terms of the MIT license.

Disclaimer

Of course, this code is not intended to be used for spamming. If you feel abused, please report your problems directly to the Twitter team.

Dependencies









Hosted by Google Code