Delete all delicious bookmarks with PHP

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";  
?>

You need to insert your username and password at the beginning of the script. After that you run it from the command line at your own risk: php script.php That’s it… The script needs a while to delete your bookmarks.


Hier gibt es keinen Kommentarbereich. Hast du etwas zu kommentieren? Dann blogge einfach selbst. Oder schreib darüber mit deinem Kommentar in einem sozialen Netzwerk deiner Wahl.