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
Comments
so THIS is why Navi and Vegeta are trollin' me...... DAMN!
LOL, I'm only responsible for the DBZNappa one. The Navi one is awesome, but (unfortunately) not my creation :P
Ah... I thought you stalked lots of Twitter pages. I even replied a few times, saying that the scouter must be broken.
Haha, nah, it's all automated :P
Nice work! Just got caught by your bot...
Me too! I think I was the last person who got tweeted at the time of posting this.
Great. Now we're gonna get Twitter spam!
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.
Someone doesn't get jokes. Really get off your high horse and find the funny side in shit, he already said he didn't write navi.
get over yourself.
Haha It actually replied me, and thats how I got to this site just now! :)
I rode my bicycle over 9000 miles around the United States and all I get is a bot reply? haha
@someone: Haha! It's funny because it's his fault now, because he posted something so easy to make, and that was probably already being used by spammers nonetheless! <laugh.gif>
Hi,
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/twit... 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?
Install the PECL OAuth extension and try again :)
I'm noticing that the example script matches not just exact strings, but any strings that contain all the elements specified in the $term..
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!
The search just uses Twitter's search API and returns the results exactly as Twitter returns them. Try putting the term in quotation marks, something like:
$twitter->addReply('"NBA JAM"', 'Reply here');
Let me know if that works :)
Seems to have worked with the quotes!
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_hum...
http://twitter.com/jake_mag...
:D
That is very weird! Posting shouldn't affect the since_id as the since_id is only used for the search, and is read from a file every time the script runs. I've posted to the DBZNappa account and it hasn't reposted any auto-replies. Very weird.
That's neat! You got me there with my tweet twitter.com/#!/pinoyeXtensi...
When i start bot
========= 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
This means that your authentication data is incorrect. Check your four authentication values (consumer key, consumer secret, token and secret) are all correct and don't have any spaces before or after them.
Well, I'm glad you explained that it was an attempt to test a bot, I spent hours trying to talk to @DBZNappa and all I got was 9000.
Hahaha, yeah, it's all automated. It won't say anything other than the automated responses, unless I log in and post something using its account :P
There is a similar Spartan bot that replies using the 300 dialogue
http://www.twitter.com/King...
Yeah, I saw a blog post by the person that made that bot. They said that they were inspired by DBZNappa. I'm happy that people are being inspired by some of my work, even if it is silly things like this!
any chance you will ever make a video explaining this a little better, i'm having a little problem comprehending a few things in the creation of this.
I don't have time to make a video at the moment, nor are my recording skills good :P
Well what about a better tutorial? You don't really explain it too thuroughly.
Yeah I don't have time to write one :(
LOL just got hit myself by it and was like... what the fuck... then saw the link to this... good shit :P
I am trying to run the script, but I get the following error:
"PHP Fatal error: Class 'OAuth' not found in /var/www/files/bot/TwitterAutoReply.php on line 22"
What am I doing wrong?
You need to install the PECL OAuth extension. On a Linux system, you should be able to do this by running "pecl install oauth".
Very creative! and a bot that doesn't retweet stuff, but just replies! :)
Haha, thanks! :)
a bot i was wondering what it was talking about !
ITS OVER 9000!!!!!!!!!!!!!!!!!!
LMAO. Nappa made my day good sir.
I got it but I didn't say 9000, I said 1000 =P
As these things happen, I found myself in need of a Twitter bot that would reply "WHAT?! NINE THOUSAND?" to any mention of "9000" on Twitter.
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.
This is hilarious! LOL XD
Well, this smells spammy...
LOL! I just got caught by this yesterday.. funny. :)
i want to make some bots too.. lol
you could create a tutorial with pictures step by step, never stirred in programção and would like to create a bot
Unfortunately I don't really have time to write a tutorial D:
Oh... I was trolled. XD @DBZNappa this is great. =))
LOL it's automated and I wanted to reply :p
What nine thousannddd :)
LOL it's automated and I wanted to reply :p
What nine thousannddd :)
Haha, amazing bot. Make it reply to "9001" too :D
I must say, I got a giggle from your WHAT, NINE THOUSAND?! Bot - nice one dude!
Hi Daniel
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
Try the instructions in this comment: https://gist.github.com/820...
in TwitterAutoReply.php you also need to make the following changes
Comment out $this->_oauth->setToken($token, $secret); and add the changes so the function looks like below:
public function setToken($token, $secret)
{
//$this->_oauth->setToken($token, $secret);
$this->_oauth->config['user_token'] = $token;
$this->_oauth->config['user_secret'] = $secret;
}
Great use of a DBZ avatar. Just got caught by your bot.
Is the Nappa Bot down? It hasn't tweeted in a few days.
It was down, but should be okay now.
Lol i was watching syndicates livestreams and he wanted 9000 likes and everyone got spammed i legitly thought you were doing it yourself then i saw bot and i was like woow q:
Alright. When I run the script it will ask me to authorize the application which is fine but once I authorize the application, it will just ask me to authorize it again the next time it runs. Any thoughts on this?
I'll post a screen shot of the issue.
http://i.imgur.com/S5i6g.png
Are you sure you entered the OAuth details correctly?
Alright, I'm getting this error Now:
========= 2012-06-11 10:14:34 AM - Started =========
Performing search for "based god"... Done, 15 results.
@BasedTrillness said: oh my god based god
PHP Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in /var/www/Twitterbot/twitterautoreply.php:82
Stack trace:
#0 /var/www/Twitterbot/twitterautoreply.php(82): OAuth->fetch('https://twitter...', Array, 'POST')
#1 /var/www/Twitterbot/twitterautoreply.php(68): TwitterAutoReply->sendReply(Object(stdClass), 'SWAG http://i.i...')
#2 /var/www/Twitterbot/example.php(12): TwitterAutoReply->run()
#3 {main}
thrown in /var/www/Twitterbot/twitterautoreply.php on line 82
Do you control him because if he's a bot he couldn't follow someone :P
Yeah, I do control him :P
so what was the navi thing?
How did you manage to work this bot all the time ?
is cron job ?
Yeah, it's a cron job that runs every 15 minutes.
my robot is a suspend by twitter :S ?
help please.
Yeah, this seems to happen sometimes. I guess I've been lucky with mine! Other people seem to have had their suspended :(
Your bot caught me today, and I even replied... lol I so love him.
Hahaha I'm glad. xD
Hahaha I'm glad. xD
www.deneme.umityagci.com/ex...
www.deneme.umityagci.com/Tw...
Code Error ?
I always get a reply from ur bot.. it's pretty awesome ^_^ tried having a convo w/it, no reply. LOL wish I could get my profile to autoreply to spammers.. I hate em! Any chance you'd know how to do that?
@DBZNappa has reached 10k+ followers! You guys know what that means...
IT'S OVER NINEDOUZAND.
WHAT? NINE THOUSAND?! :P
hey, can you help me get a bot thingy for my twitter?
over 9000
Hahaha, I love this thing. It's still goin strong.
Absolutely brilliant! I loved that unexpected response! LMAO!
this is my favorite thing
Slightly curious, how is it that DBZNappa has not been suspended for policy violation?
To be honest, I have absolutely no idea. I guess I'm just lucky? Hahaha
It works, kinda. I'm getting this error
PHP Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 403, expected HTTP/1.1 20X or a redirect)' in /path/to/script/script.php:80
Any ideas?
Your help is appreciated.
Thanks in advance
Interesting... Not sure why you'd be getting that. Are you sure your OAuth details are correct?
Nice stuff - thank you for the share. Do you think you will be updating your php twitter script anytime soon? Do you think you could build something like this autotwbot.com? Let me know - thanks.
thats fuckin cool :D
I got this error,
#!/usr/bin/php ========= 2012-10-04 1:08:44 PM - Started ========= Performing search for "over 9000"... Done, 15 results. @doM_CraZzy said: Over 9000
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in C:\xampp\htdocs\TwitterAutoReply.php:82 Stack trace: #0 C:\xampp\htdocs\TwitterAutoReply.php(82): OAuth->fetch('https://twitter...', Array, 'POST') #1 C:\xampp\htdocs\TwitterAutoReply.php(68): TwitterAutoReply->sendReply(Object(stdClass), 'WHAT?! NINE THO...') #2 C:\xampp\htdocs\example.php(12): TwitterAutoReply->run() #3 {main} thrown in C:\xampp\htdocs\TwitterAutoReply.php on line 82
=========================
Can you help me, thanks
Make sure you set your Twitter application to be read and write (not read-only)
I got the following error,
Can help me fix it ?
thanks
==================================================
#!/usr/bin/php ========= 2012-10-04 2:22:04 PM - Started ========= Please navigate to the following URL to get an authentication token: http://twitter.com/oauth/au... Once done (and you have a PIN number), press ENTER.
Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:\xampp\htdocs\TwitterAutoReply.php on line 112
Warning: fread() expects parameter 1 to be resource, string given in C:\xampp\htdocs\TwitterAutoReply.php on line 112
PIN Number:
Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:\xampp\htdocs\TwitterAutoReply.php on line 115
Warning: fread() expects parameter 1 to be resource, string given in C:\xampp\htdocs\TwitterAutoReply.php on line 115
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in C:\xampp\htdocs\TwitterAutoReply.php:119 Stack trace: #0 C:\xampp\htdocs\TwitterAutoReply.php(119): OAuth->getAccessToken('https://twitter...', '', '') #1 C:\xampp\htdocs\TwitterAutoReply.php(58): TwitterAutoReply->doAuth() #2 C:\xampp\htdocs\example.php(12): TwitterAutoReply->run() #3 {main} thrown in C:\xampp\htdocs\TwitterAutoReply.php on line 119
What version of PHP are you using?
Why did you pick that number?
http://knowyourmeme.com/mem...
dude your bot makes me laugh so hard hahaha, congrats!
Glad you like it.
I wish I was a lucky as you are with not being caught by the Twitter police! The majority of the bots that I make are suspended within a week. This one and the Yoda one that has something like 780,000 tweets just blow my mind!
It's crazy right? Haha. Maybe making a bot that replies just a few times per hour would make it less likely to be suspended.
I'll give you over 9000 dollars to install this on my computer. P.S. LOVE this!
"which I think is pretty cool. :)"
No, not cool. Very annoying actually. Get a life, dude
Prolly has one unlike yourself
Friend, tcan you show me the command line to execute the cron?
I set the parameters to twice/hour at cpanel, but I don't know the comand line, this shoul looks like this: php -q /home/USER/public_html/bot/example.php ???
Yeah, that looks correct. Add " > /home/USER/public_html/bot/log.txt 2>&1" to the end so the output will go into a file called "log.txt". Check the log.txt after a while to see the output from the cron job.
@daniel I am very interested with your apps, can you teach me how to set up this twitter application? I am willing to pay for your service if your are willing to teach me how this work. :) email me @ ditzemojon@gmail.com
hey there..
@daniel I am very interested with your apps, can you teach me how to set up this twitter applicationhttps://twitter.... I am willing to pay for your service if your are willing to teach me how this work. :) email me @ ditzemojon@gmail.com. Thanks! I'll wait for your email......
@daniel @DBZNappa I am very interested with your apps, can you teach me how to set
up this twitter application? I am willing to pay for your service if
your are willing to teach me how this work. :) email me @
ditzemojon@gmail.com
Hey could you teach me how to successfully run this scrip in layman's language. I am not a programmer.
I seriously cried with laugher when this hit. I told co-workers. This was fantastic.
Add "over9000" to his username so we can watch him reply to himself forever.
The twitter bot should have commands like stats and ignore.
Dude its awesome!!! In thought it was awesome seeing the name and phase repeated to someone talking about mine craft... I soon realized it was a bot, as In was replying to at least a hundred people a minute
hey daniel.. is this affect with the change of twitter API next month? Thanks..
Not too sure... I'll have to look at the code again and see.
i follow you everywhere just to keep me update to the new code.. :D
Thanks again.
Dude thats annoying but pretty cool...
WHAT? NINE THOUSAND?! :D
Hey Sir,
Whats the version PHP i need to Install it?
What any Free Hosting to install it sir?
I'm not sure about free hosting, I haven't used shared hosting for a long time. You'll need SSH access and not all hosts provide it.
This bot just made my day.
hey, I know some html & css only. could u plz show me how to make the bot work (I have a godaddy account with cpanel). my email: justin-farmer@yandex.com
This bot of yours has brought it to my attention that you should program a bot that trolls James Iha
Hello, I tried to make an auto reply bot like this one but after the first 13 replies I got the account blocked the reason was replying to people too often, or something like that, how did you avoid that?
Daniel can you help me
You fucker....I nearly replied to the tweet. Good work sir!
Hey Daniel, can you please make a version of this for hosting site user like me. So our bot online 24/7 even our computer is off.
You can already use it on a hosted server as long as you have SSH access. If you have cPanel or similar, you could probably set it up as a cronjob via that, but I haven't done that in ages.
I just want to let you know that im being spammed by your bot, he sent me 4 messages (every 5minutes) it is supposed to happen ? Do i need to block him ?
hey Daniel, I know some html & css only. could u plz show me how to make
the bot work (I have a godaddy account with cpanel). my email:
justin-farmer@yandex.com
lol :)
Hi Daniel..
Can it also work for shared hosting like Hawkhost? I don't know exactly if it has something like PECL OAuth or SSH Access.. THanks in advance..
how do i use this? what do i need? how do i install it?
hi, i want similar site like tweetpi.com can anyone give me?
urgent requirement
We sell the Best Mosque Carpets all over UAE in the best quality and cheap rates. We have a large number of variety in carpets and a Discount of 20%.