pavondunbar
Newbie
- Feb 20, 2008
- 41
- 89
Hi BHW...
I don't post on here that much, but I wanted to share this simple PHP script that will help you mass unfollow (or follow) 150 Twitterers every hour.
Here's how to adjust the code:
1) Open Notepad.
2) Copy the code below EXACTLY as shown.
3) Where it says "PUT YOUR TWITTER USERNAME HERE"...well...you know what to do.
4) Do the same for where it says "PUT YOUR TWITTER PASSWORD HERE"
5) Save as FILENAME.php
6) Upload the file to your server
7) Go to http://www.YOURDOMAIN.com/FILENAME.php
8) If everything goes well, you will see that you're unfollowing people that are not following you back (because everyone hates that...
)
*******************************************************
<?php
// Created by Pavon Dunbar / TwitterMinisite.com / TheCasinoAndPokerSite.com / [email protected]
// April 2010 / Twitter / API v1
// Remember to change USERNAME and PASSWORD below
// Modify/redistribute the script as you see fit, but please leave this header intact
// Change this if required
define("USERNAME", "PUT YOUR TWITTER USERNAME HERE");
define("PASSWORD", "PUT YOUR TWITTER PASSWORD HERE");
// Put all SimpleXML Object values into array so we can parse them with PHP's array tools
function simplexml2array($xml) {
if (get_class($xml) == 'SimpleXMLElement') {
$attributes = $xml->attributes();
foreach($attributes as $k=>$v) {
if ($v) $a[$k] = (string) $v;
}
$x = $xml;
$xml = get_object_vars($xml);
}
if (is_array($xml)) {
if (count($xml) == 0) return (string) $x; // for CDATA
foreach($xml as $key=>$value) {
$r[$key] = simplexml2array($value);
}
if (isset($a)) $r['@'] = $a; // Attributes
return $r;
}
return (string) $xml;
}
// Calls Twitter API and returns SimpleXML Object
function api($url, $method="GET"){
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, USERNAME.":".PASSWORD);
$buffer = curl_exec($ch);
curl_close($ch);
return(simplexml_load_string($buffer));
}
if($error = api("http://twitter.com/account/verify_credentials.xml")->error){ die("<strong>Error: </strong>$error"); }
// Gets a list of friends IDs and followers IDs
$friends = simplexml2array(api("http://twitter.com/friends/ids.xml"));
$friends = $friends['id']; // Get rid of the multi-dimension variable
$followers = simplexml2array(api("http://twitter.com/followers/ids.xml"));
$followers = $followers['id']; // Get rid of the multi-dimension variable
// Create arrays for queueing up follows/unfollows
$unfollowQueue = array();
$followQueue = array();
// Populate the queues
foreach(array_diff($friends, $followers) as $id){ array_push($unfollowQueue, $id); } // FRIENDS that are not in FOLLOWERS (unfollow)
foreach(array_diff($followers, $friends) as $id){ array_push($followQueue, $id); } // FOLLOWERS that are not in FRIENDS (follow)
// Process unfollow queue first
echo("<strong>Unfollowing...</strong><br />");
foreach($unfollowQueue as $id){
$xml = api("http://twitter.com/friendships/destroy/$id.xml", "DELETE");
if($error = $xml->error){
echo("<span style='color:red;'>[ ERROR ]</span> $id ($error) <br />");
} else {
echo("<span style='color:green;'>[ SUCCESS ]</span> $id <br />");
}
}
echo("<br /><br />");
echo("<strong>Following...</strong><br />");
foreach($followQueue as $id){
$xml = api("http://twitter.com/friendships/create/$id.xml", "POST");
if($error = $xml->error){
echo("<span style='color:red;'>[ ERROR ]</span> $id ($error) <br />");
} else {
echo("<span style='color:green;'>[ SUCCESS ]</span> $id <br />");
}
}
?>
*******************************************************
A few notes:
1) Please only unfollow once a day. If Twitter sees you unfollowing people frequently, they may ban your account. I will NOT be held responsible if you abuse this script, so use it wisely.
2) The script will only allow you to unfollow/follow 150 people MAX per hour.
That's it! You guys are great. Thanks to everyone on BHW for making this forum as great as it is.
pavondunbar
Twitter @pavondunbar
I don't post on here that much, but I wanted to share this simple PHP script that will help you mass unfollow (or follow) 150 Twitterers every hour.
Here's how to adjust the code:
1) Open Notepad.
2) Copy the code below EXACTLY as shown.
3) Where it says "PUT YOUR TWITTER USERNAME HERE"...well...you know what to do.
4) Do the same for where it says "PUT YOUR TWITTER PASSWORD HERE"
5) Save as FILENAME.php
6) Upload the file to your server
7) Go to http://www.YOURDOMAIN.com/FILENAME.php
8) If everything goes well, you will see that you're unfollowing people that are not following you back (because everyone hates that...
*******************************************************
<?php
// Created by Pavon Dunbar / TwitterMinisite.com / TheCasinoAndPokerSite.com / [email protected]
// April 2010 / Twitter / API v1
// Remember to change USERNAME and PASSWORD below
// Modify/redistribute the script as you see fit, but please leave this header intact
// Change this if required
define("USERNAME", "PUT YOUR TWITTER USERNAME HERE");
define("PASSWORD", "PUT YOUR TWITTER PASSWORD HERE");
// Put all SimpleXML Object values into array so we can parse them with PHP's array tools
function simplexml2array($xml) {
if (get_class($xml) == 'SimpleXMLElement') {
$attributes = $xml->attributes();
foreach($attributes as $k=>$v) {
if ($v) $a[$k] = (string) $v;
}
$x = $xml;
$xml = get_object_vars($xml);
}
if (is_array($xml)) {
if (count($xml) == 0) return (string) $x; // for CDATA
foreach($xml as $key=>$value) {
$r[$key] = simplexml2array($value);
}
if (isset($a)) $r['@'] = $a; // Attributes
return $r;
}
return (string) $xml;
}
// Calls Twitter API and returns SimpleXML Object
function api($url, $method="GET"){
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, USERNAME.":".PASSWORD);
$buffer = curl_exec($ch);
curl_close($ch);
return(simplexml_load_string($buffer));
}
if($error = api("http://twitter.com/account/verify_credentials.xml")->error){ die("<strong>Error: </strong>$error"); }
// Gets a list of friends IDs and followers IDs
$friends = simplexml2array(api("http://twitter.com/friends/ids.xml"));
$friends = $friends['id']; // Get rid of the multi-dimension variable
$followers = simplexml2array(api("http://twitter.com/followers/ids.xml"));
$followers = $followers['id']; // Get rid of the multi-dimension variable
// Create arrays for queueing up follows/unfollows
$unfollowQueue = array();
$followQueue = array();
// Populate the queues
foreach(array_diff($friends, $followers) as $id){ array_push($unfollowQueue, $id); } // FRIENDS that are not in FOLLOWERS (unfollow)
foreach(array_diff($followers, $friends) as $id){ array_push($followQueue, $id); } // FOLLOWERS that are not in FRIENDS (follow)
// Process unfollow queue first
echo("<strong>Unfollowing...</strong><br />");
foreach($unfollowQueue as $id){
$xml = api("http://twitter.com/friendships/destroy/$id.xml", "DELETE");
if($error = $xml->error){
echo("<span style='color:red;'>[ ERROR ]</span> $id ($error) <br />");
} else {
echo("<span style='color:green;'>[ SUCCESS ]</span> $id <br />");
}
}
echo("<br /><br />");
echo("<strong>Following...</strong><br />");
foreach($followQueue as $id){
$xml = api("http://twitter.com/friendships/create/$id.xml", "POST");
if($error = $xml->error){
echo("<span style='color:red;'>[ ERROR ]</span> $id ($error) <br />");
} else {
echo("<span style='color:green;'>[ SUCCESS ]</span> $id <br />");
}
}
?>
*******************************************************
A few notes:
1) Please only unfollow once a day. If Twitter sees you unfollowing people frequently, they may ban your account. I will NOT be held responsible if you abuse this script, so use it wisely.
2) The script will only allow you to unfollow/follow 150 people MAX per hour.
That's it! You guys are great. Thanks to everyone on BHW for making this forum as great as it is.
pavondunbar
Twitter @pavondunbar