So I thought I'd finally write a little blog post about a Twitter bot I made a while ago. A few people emailed me asking for the source code, so I had previously posted about it on webDevRefinery, but never on my own blog. Basically all the bot does is search for whenever people mention "over 9000" or "over nine thousand", and replies with "WHAT, NINE THOUSAND?!". Pretty simple, but I wanted to learn about using the Twitter API. It seems to have inspired the creation of other Twitter bots, like AnnoyingNavi and The Spacesphere, which I think is pretty cool. :).
The source code is available as a Gist on Github. It is written in PHP and requires the PECL OAuth extension to be installed. I think it's a pretty good example of a simple "search and reply" Twitter bot, that could easily be extended to do more useful things.
Until next time,
— Daniel
53 comments
Thanks very much for your 'experiment'!
AnnoyingNavigation is already harassing me with stupid tweets, just because I tweeted something about Zelda.
And guess what? I have to do something to stop receiving crap I never solicited in the first place!
You are officially a Twitter dickhead.
get over yourself.
I'm just playing around with this script and I got a error when I run this on my server.
"PHP Fatal error: Class 'OAuth' not found in /chroot/home/xxx/domain.com/html/folder/twitterautoreply.php on line 19"
Running from shell with package pcre-6.6-6.el5_6.1.x86_64 installed and updated. Any idea why I get this error?
So if I'm searching for "NBA JAM" (just an example), it matches "I love playing NBA JAM", but it also matches "Gotta jam for now, NBA game on in a bit."
How can I specify that I want the string exactly?
Thanks for everything!
$twitter->addReply('"NBA JAM"', 'Reply here');
Let me know if that works :)
There are a bunch of things I want to try with this script-- I'll post back here as I figure stuff out..
Have you noticed that if you post to the timeline that is connected to the app, it seems to mess with the since_id parameter? For instance, if I retweet to one of my followers the last "batch" of users gets hit for a second round of auto-replies.
http://twitter.com/finn_human_boy
http://twitter.com/jake_magicdog
:D
========= 2011-09-01 8:14:12 PM - Запущен ========= Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in /usr/home/test/data/www/twitter/twitterautoreply.php:101 Stack trace: #0 /usr/home/test/data/www/twitter/twitterautoreply.php(101): OAuth->getRequestToken('https://api.twi...') #1 /usr/home/test/data/www/twitter/twitterautoreply.php(51): TwitterAutoReply->doAuth() #2 /usr/home/test/data/www/twitter/index.php(10): TwitterAutoReply->run() #3 {main} thrown in /usr/home/test/data/www/twitter/twitterautoreply.php on line 101
PECL OAuth extension installed
http://www.twitter.com/KingLeonidaz_
"PHP Fatal error: Class 'OAuth' not found in /var/www/files/bot/TwitterAutoReply.php on line 22"
What am I doing wrong?
Thank you for writing this, it saves me from doing so. I'd be interested to hear how you managed to deduce my need some six months before I myself became aware of that need, but this can wait for another time.
i want to make some bots too.. lol
What nine thousannddd :)
What nine thousannddd :)
Hope you are doing well.
o am new to twitter api and want to implement twitter bot. i just want how to install pecl package i have used this bot with tmhoauth but not working for me :( its just search for tweets but not reply for them because it gives error on this code
public function setToken($token, $secret)
{
$this->_oauth->setToken($token, $secret);
}
can you please tell me some replacement code for this?
thanks