Learn WordPress
Home » Script

Simple Twitter Auto Follow Script

twitter auto follow script

To increase your twitter follower first you need to follow each people and then removed people that doesn’t follow you back. But it would be bored job and waste your time. Might be some free online service may help you to remove all immediately people who doesn’t follow you back, but to follow some specified keyword e.g. “new york, washington, computer, celebrity, etc.” it will waste your time.

Twitter Auto Follow Script

This is simple single script for Twitter auto follow. Write in PHP, simply as it seem after you have edit your twitter username, your twitter user password and your target keyword, you just need a hosting and host the script then called the script using browser (Never the best than Mozilla Firefox, rite?!).

Code is released as Open Source and use it as you wish.

<?php

// Twitter Auto-follow Script by Dave – http://www.aming.info

// Set the twitter user
$user = "your twitter username";
$pass = "your twitter user password";

// Set the term keyword you want to follow (e.g. "soccer")
$term = "your target keyword";

// Get already followed
$userApiUrl = "http://twitter.com/statuses/friends.json";

$ch = curl_init($userApiUrl);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$apiresponse = curl_exec($ch);

curl_close($ch);

$followed = array();

if ($apiresponse) {
$json = json_decode($apiresponse);
if ($json != null) {
foreach ($json as $u) {
$followed[] = $u->name;
}
}
}

$userApiUrl = "http://search.twitter.com/search.json?q=" . $term . "&rpp=100";

$ch = curl_init($userApiUrl);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$apiresponse = curl_exec($ch);

curl_close($ch);

if ($apiresponse) {
$results = json_decode($apiresponse);
$count = 20;

if ($results != null) {

$resultsArr = $results->results;

if (is_array($resultsArr)) {

foreach ($resultsArr as $result) {

$from_user = $result->from_user;

if (!in_array($from_user,$followed)) {

$ch = curl_init("http://twitter.com/friendships/create/" . $from_user . ".json");
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"follow=true");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$apiresponse = curl_exec($ch);

if ($apiresponse) {
$response = json_decode($apiresponse);

if ($response != null) {
if (property_exists($response,"following")) {
if ($response->following === true) {
echo "Now following " . $response->screen_name . "\n";
} else {
echo "Couldn’t follow " . $response->screen_name . "\n";
}
} else {
echo "Follow limit exceeded, skipped " . $from_user . "\n";
}
}

}

curl_close($ch);

} else {
echo "Already following " . $from_user . "\n";
}

}

}

}

}

?>

Or you can use Twitter Auto Follow and Twitter Auto Unfollow for free.

FREE Cloud Storage