Today I wanted to delete all my del.icio.us bookmarks because they were outdated and I wanted to reimport them. But the delete method on the website is really lame and even the Firefox plugin is not able to delete all bookmarks without selecting them manually and delete them one-by-one… So I took the del.icio.us API and wrote a small PHP script to fetch all bookmarks and delete them. All you need to install is a PHP CLI and the Curl-Plugin: aptitude install php5-cli php5-curl
Now copy the source and safe the script:
<?php
$Username = ''; // insert your username here
$Password = ''; // insert your password here
$Return = "";
$ch = curl_init("https://api.del.icio.us/v1/posts/all");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $Username .":". $Password);
$Return = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($Return);
$i = 0;
foreach($xml->post as $post) {
$DeleteUrl = (string) $post->attributes()->href;
$Url = "https://api.del.icio.us/v1/posts/delete?url=". urlencode($DeleteUrl);
echo "trying to delete ". $DeleteUrl ." ";
$ch = curl_init($Url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $Username .":". $Password);
$DeleteReturn = curl_exec($ch);
if(strstr($DeleteReturn, "<result code=\"done\"")) {
echo "... done\n";
} else {
echo "... failed\n";
}
curl_close($ch);
$i++;
}
echo "Deleted {$i} URLs\n";
?>