Everyone who has a Twitter account wants to have as many followers as possible. To help “tweeters” get more “twadds”, I have wrote this PHP script that will automatically search Twitter to find “tweeple” to follow and it will also follow “tweeple” that are already following you. Okay, thats enough of the Twitterspeak so lets get down to how to use this script.

The first thing that your going to have to do to use this script is create a new Twitter application by going to https://dev.twitter.com/apps/new (If you’re not already signed in, you will have to sign in with the Twitter account that you want to be used with this script). For the name, you can enter “[Users] Auto Follow Tool” (must be unique) and for the description, you can enter “A tool that gets more Twitter followers”. You will also need to enter a website which can be pretty much anything because this “twapplication” is just going to be used by you. Finish creating the application by agreeing to the user agreement and entering the captcha code.

Once you have created the application, then you are going to have to add read & write access and create a access token. To add read & write permissions, go to the “Settings” tab and change the access to “Read and Write”, then click the button at the bottom of the page to update the settings. Next, you will need to create a access token by going back to the “Details” tab and click “Create my access token” at the bottom of the page. Usually the access tokens aren’t shown right away, so you will need to refresh the page a few times. Once they are shown, please note the “Consumer key”, “Consumer secret”, “Access token”, and “Access token secret” somewhere as we will need them to configure the PHP script.

If you have not already downloaded the PHP script, you can download the auto follow script from here. Once you have downloaded the file, extract the archive to a directory and open “auto-follow.php” in a text editor (such as Notepad++).

The first thing your going to want to change is the application keys, so using the keys that we got earlier enter them into their corresponding space (ie: replace “YOUR CONSUMER KEY” with the consumer key).
[highlight lang=”php”]
The next thing to change is the search query, which can be no longer than 1000 characters and you can utilize the Twitter search operands that are explained at http://dev.twitter.com/docs/using-search under ‘Search Operators’.
[highlight lang=”php”]define(‘SEARCH_QUERY’, ‘YOUR SEARCH QUERY’);[/highlight]
If you would like to send your new followers a DM (Direct Message), then you can enter the message in the next define (but remember its like a tweet so it cannot be longer than 140 characters and links are automatically truncated to 20 characters) or if you don’t want to send a DM you can just leave that blank.
[highlight lang=”php”]define(‘DIRECT_MESSAGE’, ‘Thanks for the follow!’);[/highlight]
We will now need to test and make sure that this script is running correctly. To do this, upload the files to a web server (including OAuth.php and twitteroauth.php as well) and navigate to the script by going to http://yourwebsite.com/xyz/auto-follow.php?action=search or http://yourwebsite.com/xyz/auto-follow.php?action=follow-back. If the script completed successfully, then you should see something like “Following X new users”, or if it failed you may get something like “Unable to authenticate with Twitter” which means your keys are probably entered incorrectly.

For this next part, your going to need cron configured on your web server. If your not sure if it is, I would contact your hosting provider to find out if its available and how you can use it. I recommend that this script be ran every hour because Twitter as a limit of 350 requests per hour and if your getting lots of results, this script will not function as it should if its not run every hour. I also have it configured so it rotates between searching for followers the first hour, and then the second hour it follows your followers back. Below is an example cron job so the script is run once an hour:

0 * * * * php -q /path/to/auto-follow.php >/dev/null 2>&1

(I added “>/dev/null 2>&1” to the end of the command so your not getting an email saying that the cron job completed every hour)

So that’s it! if you have any comments, please leave them below. All the best in getting more twadds.

Download Now:PHP Script / 11 KB

Download Not Available On Mobile Devices

Update #1: Thanks to Mumin for notifying me of a bug when trying to run this script using XAMPP For Windows. The problem was with the variable $resp->following not being set causing an error to show up saying “Undefined property: stdClass::$following”. I have corrected this problem by adding a check for the variable. I also added a check to make sure the TwitterOAuth library is included.

Update #2: The script has been updated to work with Twitter API v1.1 (since Twitter API v1 is no more).