Archive for the ‘TwitterBot’ Category

2 Comments »June 27th, 2009

Twitter Bot Script – A Full Blown Bot Package

A few months ago I did a post about how to make a Twitter bot with php. The post is currently ranking number one for making a Twitter bot and I was getting tons of emails on tyler.tc on how to make the script more functional, and basically just do more. I put some ideas down and sent them to a few friends and got a great response. After putting some code together and releasing it online, TwitterBotScript or “TBS” has become a hit.

The reason being: Its simple to use, its constantly evolving, it allows you to expand your Twitter account (and marketing efforts) extremely fast, and its FREE. Think of TBS as an open source twitter bot script. Not only can you download it but its easy to build on with your own ideas and a little PHP experience.

Twitter Bot Script comes with what has been dubbed the TBS Toolkit, lets look at some features:

  • Full GUI tweet management including “Show Status” which allows you to pause that tweet from appearing in your activities.
  • Import tweets via a CSV file with the ability to set their status and type on the fly.
  • Create globally used tweets, or create special tweets to be used only for replies and direct messages.
  • The Mention Reply Tool will allow you to see all the recent @your tweets and automatically respond to them using the bulk responder option, or quickly write up a custom response. TBS will also keep track of the tweets you respond to so you don’t continually send duplicate responses like with other bot scripts.
  • The Make Friends Tool is another awesome tool only available from TwitterBotScript. This tool will give you a bunch of new ways to make friends on Twitter. Account sourcing will allow you to randomly follow users from your friends or followers (toggle) while allowing you to reselect the target, and the required amount of followers for each person you try to follow on the fly. You can also find new friends via keyword searching, or by directly inputting lists of user names.
  • TBS of course includes a status update tool that works just like your Twitter homepage.
  • Sleep Mode will allow you to randomize the time at which your tweets appear on Twitter. When you automate with CRON, your script is run at the same time interval every time. By using sleep mode, the script will essentially sleep for a random amount of time making your tweeting look more natural to Twitter users.
  • Tweet counter. So lets say you don’t have a larger number of tweets to work with and you don’t want to keep repeating them. You can globally set a tweet limit in TwitterBotScript limiting the number of times each message can be used.
  • API Rate Limiting integration.

Another bonus is Twitter bot script requires almost nothing to run... A basic installation of Apache, MySQL, and PHP (and cURL of course) will do the job. But you will need CRON in order to use automation. In the next release, Twitter Bot Script will have a synthetic version of CRON like what WordPress uses.

Twitter Bot Script has been installed 598 times since it was released four days ago. I think with a little push Twitter Bot Script could easily become the king. I looked around today at the competition and most of the stuff out there is either very basic or very expensive.  This puts Twitter Bot Script at a distinct advantage as users get an advanced tool set that is constantly seeing additions and revisions, for free. Yeah, there is definitely work to be done but that’s the point. As I get more and more emails for I’ll know what direction to move in.

So go download Twitter Bot Script and play around with it. You don’t have to be marketing your Micheal Jackson t-shirts to have fun with Twitter Bot Script. Its great for easily finding new friends and exposure.

Also: If your handy with PHP and working with APIs, shoot me an email if your interested in working on this project.

No Comments »November 3rd, 2008

Expanding On TwitterBot – Keep Track of Used Tweets

Now that you know how to make a Twitter bot you may be looking to add some more functionality to it. One problem you may run into after some time is that you keep recycling or re-sending the same messages to Twitter. For example, you have 100 facts about your self and you don’t want any of them to appear twice but you want everything to be automated. How do you do this? Easy, just add a status field to your `tweets` table.

Step 1 – Add the field.
To add the field you can use the simple graphical interface in phpMyAdmin or use the SQL tab (or alternative) to run this code:

ALTER TABLE `tweets` ADD `status` VARCHAR(10) NOT NULL;

What this will do is create a new field in your tweets table with 10 characters of space for that messages status. We will be setting them all to “ready”, and later changing our PHP code to update them as we go along.

Step 2 – Set all tweets to ready.
After you have the new field added to your database you will need to set all of the tweets you want to use to ‘ready’ status. In this example, only tweets with the status set to ‘ready’ can be randomly selected.

While inside of phpMyAdmin (SQL tab) or what ever tool you use, go to the page that allows you to run MySQL commands on your tables and enter this code:

UPDATE `tweets` SET `status` = ‘ready’

Alternatively you can pick which ones you want to use if you already have some tweets that you wish not to recycle. This SQL command will update every tweet/message you have in your database so use it wisely.

Step 3 – Modify PHP to update tweet status in database.
Our third an final step is to modify the php script so it will change the status of every used tweet. To do this, we will make a few simple changes to our original code.

First off, we have to change the MySQL query so it will only pull random messages with “ready” status:

$result = mysql_query (“SELECT * FROM tweets WHERE status = ‘ready’ ORDER BY RAND() LIMIT 1);

For our second change, we will need to get the ID number of the tweet from the database and pass it to the sendTweet() function we will modify in a moment:

while($row = mysql_fetch_array($result)){

$tweet = “$row[tweet]“;

$tweetID = “$row[id]“;

sendTweet($tweet, $tweetID);

}

Then we modify our sendTweet() function to handle the tweet’s ID, and then change its status if the message is successfully sent to Twitter:

function sendTweet($msg, $idoftweet){

$username = ‘TWITTER-USER-NAME’;

$password = ‘TWITTER-PASS’;

$url = ‘http://twitter.com/statuses/update.xml’;

$curl_handle = curl_init();

curl_setopt($curl_handle, CURLOPT_URL,$url);

curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_handle, CURLOPT_POST, 1);

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, “status=$msg);

curl_setopt($curl_handle, CURLOPT_USERPWD,$username:$password);

$buffer = curl_exec($curl_handle);

curl_close($curl_handle);

if (empty($buffer)) {

echo ‘fail’;

} else {

echo ’success’;

mysql_query(“UPDATE `tweets` SET `status` = ‘used’ WHERE id = ‘$idoftweet’”);

}

Now it’s all ready to role. Now every time a message is pulled from the database and sent to Twitter (successfully) it will have it’s status changed to “used” taking it out of the possible messages to send. Just upload your new php file, re-activate your CRON job and have some fun.

20 Comments »October 31st, 2008

How To Make A Twitter Bot With PHP In Five Minutes

There are quite a few uses I could think of for an automated Twitter bot that posts new tweets for you throughout the day. While this sounds like it would be a hard task it’s actually quite easy and a great project for anyone who wants to learn how to use the Twitter API within PHP. Lets get started.

Step 1 – Create your database.

When creating your database there are a number of things you may want to think of ahead of time. For the sake of making things easy I chose to tone down the code I use and show you how it works. We will create a simple table to store all of the random tweets in.

CREATE TABLE `tweets` (

`id` INT(11) NOT NULL AUTO_INCREMENT,

`tweet` VARCHAR(140) DEFAULT NULL,

PRIMARY KEY (`id`)

)

Run that SQL and you should have a new “tweets” table in your chosen database. Notice how we limited the `tweet` field to 140 characters as well so we don’t have tweets that are too long to appear on Twitter.

Step 2 – Create the PHP to send the tweet.

The next step is to create a php script that will randomly select one of your tweets, and then send it to your Twitter account via Twitter’s API. While this sounds complicated, its very easy to do.

<?php

mysql_connect(“localhost”, “USERNAME”, “PASSWORD”) or die(‘Could not connect to database’);

mysql_select_db(“DATABASE”) or die(‘Could not select database’);

$result = mysql_query (“SELECT * FROM tweets ORDER BY RAND() LIMIT 1″);

while($row = mysql_fetch_array($result)){

$tweet = “$row[tweet]“;

sendTweet($tweet);

}

function sendTweet($msg){

$username = ‘TWITTER-USER-NAME’;

$password = ‘TWITTER-PASS’;

$url = ‘http://twitter.com/statuses/update.xml’;

$curl_handle = curl_init();

curl_setopt($curl_handle, CURLOPT_URL, “$url”);

curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_handle, CURLOPT_POST, 1);

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, “status=$msg”);

curl_setopt($curl_handle, CURLOPT_USERPWD, “$username:$password”);

$buffer = curl_exec($curl_handle);

curl_close($curl_handle);

if (empty($buffer)) {

echo ‘fail’;

} else {

echo ’success’;

}

}

?>

Not to bad right? Our custom sendTweet() function pretty much takes care of all the dirty work in sending the message to Twitter. Just make sure you edit the code with your password and username for Twitter, and the MySQL login. Once you have your database populated you are all good to go and test the script to see if it works. Just upload it, run it, and you should see either “fail” or “success” on your screen.

Step 3 – Automate with CRON.

After going to Twitter and checking your account to confirm everything is copacetic, it’s time to let your monster loose. Depending on what host you use, CRON access may or may not be available to you. Luckily for me I am hosted with MediaTemple so this is not a problem.

  • Script Location - When using CRON you normally want to upload the file being run into a folder that nobody has access to from the web (root). After you have it in this location, just plug it into CRON with ‘php’ in front of it. Example: php /home/user/root/TwitterBot.php
  • Set The Time - I don’t think I have ever used a control panel that required you to manually enter the time format… I’m pretty sure most people use cPanel which also has drop downs to select when you would like the script to run. I like to run my Twitter bot every 25 minuets or so to keep my Twitter account fresh.

That’s it! Not to hard right… If you have any in-depth questions on the code or need help, feel free to leave a comment. Also leave one if you have usage ideas, new features that could make the script better. As you can now see, this is a valuable tool to have in your chest.

UPDATE 5/8/2009

I have released a full blown version of the script packed with features and a complete backend GUI. This has proven to be a great Twitter marketing too! Unlike all the others, I support mine and its not a billion dollars. Check out the site for all the details.

Get Twitterbotscript now!