/ Published in: PHP
Expand |
Embed | Plain Text
// 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) { } else { } } } // ************************************************** // 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"){ $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)); }
You need to login to post a comment.
