/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 1. Validate your credentials $validate = api("http://twitter.com/account/verify_credentials.xml"); if ($validate->error) { } // 2. Get a list of your friends IDs $friends = simplexml2array(api("http://twitter.com/friends/ids.xml")); $friends = $friends['id']; } else { echo "Error getting friends!"; exit; } // 3. Unfollow everyone! foreach($friends as $f){ $xml = api("http://twitter.com/friendships/destroy/" . $f . ".xml", "DELETE"); if ($error = $xml->error) { echo "<b>ERROR:</b> " . $f . "(" . $error. ")<br />"; } else { echo "Successfully unfollowed: " . $f . "<br />"; } } } // ************************************************** // Functions // convert SimpleXML Object into an array function simplexml2array($xml) { $attributes = $xml->attributes(); foreach($attributes as $k=>$v) { if ($v) $a[$k] = (string) $v; } $x = $xml; } foreach($xml as $key=>$value) { $r[$key] = simplexml2array($value); } return $r; } return (string) $xml; } // Calls Twitter API and returns SimpleXML Object function api($url, $method="GET"){ }
Comments
