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 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!
I've waiting so long and it's happens! Holy gods! :)
You're welcome Alex ;) Let me know how it goes.
[…] This post was mentioned on Twitter by kovshenin, Stancu Daniel. Stancu Daniel said: RT @kovshenin: #Twitter Robot in #PHP: #Twibots Draft http://goo.gl/fb/nouu #robotics […]
Social comments and analytics for this post…
This post was mentioned on Twitter by kovshenin: #Twitter Robot in #PHP: #Twibots Draft http://goo.gl/fb/nouu #robotics…
Nice, but where is class.twitter.php? It's not included in the zip.
Perhaps I forgot to remove the require line. The robot shouldn't use class.twitter.php because it's using the OAuth version.
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
Joe, the first warning says it all, fetch_rss called without a url. Did you provide it with a valid Atom/RSS url?
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
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?
Jason, which version of PHP are you running?
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?
Thanks!
WHERE PUT FEED
Warning: MagpieRSS: fetch_rss called without a url in /home/best/public_html/tw/rss_fetch.inc on line 238
Warning: Invalid argument supplied for foreach() in /home/best/public_html/tw/cron.php on line 300
Alex, are you familiar with Python?