del.icio.us API
You know what del.icio.us is: a social bookmark service, now bought by Yahoo. You can create a free account and add your website bookmarks, even share with others.
They also released some API, but in my opinion very limited. All you can do is to manage your own bookmarks (links) with their tags and bundles. You can't do searches on popular websites and tags, or last added bookmarks.
To use it from any application or website you need a free account. All API help files are available at del.icio.us/help/api. They also provide HTML, RSS, JSON & JavaScript access (see help page).
The most important function (page), I think, is posts/add, which add a new link to your online account. You can do this operation from your browser openning
http://username:password@del.icio.us//api/posts/add?url=…&description=…URL title…&extended=…URL description…&tags=… tags…
You can create such a link even from JavaScript and call this page. One simple solution from JavaScript is to use new Image(), even if the value returned is not an image:
var img=new Image();
img.src='http://..full URL as above …';
When everything was done right is returned
<result code="done" />
otherwise would be:
<result code="something went wrong" />
Here's some PHP code to add a new bookmark to your account, in 2 simple ways:
function deliciousAdd($user, $pass, $url, $description, $extended, $tags) {
$r=file("http://{$user}:{$pass}@del.icio.us/api/posts/add?url=".urlencode($url).
"&description=".urlencode($description)."&extended=".urlencode($extended).
"&tags=".urlencode($tags));
return ($r[1]=="<result code=\"done\" />");
}function deliciousAdd2($user, $pass, $url, $description, $extended, $tags)
{
$domain="del.icio.us";
$socketConnection = fsockopen($domain, 80, $errno, $errstr);if (!$socketConnection) {
echo("Network error: $errstr ($errno)");
} else {
$tmp = '';
fputs($socketConnection,
"GET /api/posts/add?url=".urlencode($url).
"&description=".urlencode($description)."&extended=".urlencode($extended).
"&tags=".urlencode($tags).
" HTTP/1.0\r\nAuthorization: Basic ".base64_encode($user.":".$pass)."\r\n".
"Host: $domain\r\nConnection: close\r\n\r\n");while (!feof($socketConnection)) {
$tmp .= fgets($socketConnection, 128);
}fclose ($socketConnection);
}
return(strpos($tmp,"<result code=\"done\" />"));
}
They return TRUE or FALSE, depends on the response and could be use like:
deliciousAdd($username,$password,
"http://Yahoo.com","Yahoo!","Yahoo","yahoo");deliciousAdd2($username,$password,
"http://Yahoo.com","Yahoo!","Yahoo","yahoo");
Simple, isn't it?