Press enter to see results or esc to cancel.

Wanna buy Bitcoin, and start winning? Just click for join >

del.icio.us bookmarks in PHP

This tutorial uses PHP5 to download and cache your recent bookmarks in RSS format from the Delicious API, then displays them in a HTML unordered list.

<?
function get_delicious()
{
$cache = dirname(__FILE__) . '/caches/delicious';
if(filemtime() < (time() - 300))
{
mkdir(dirname(__FILE__) . '/caches', 0777);
$url = 'https://api.del.icio.us/v1/posts/recent?count=10';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// add delicious.com username and password below
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
$data = curl_exec($ch);
curl_close($ch);
$cachefile = fopen($cache, 'wb');
fwrite($cachefile, $data);
fclose($cachefile);
}
else
{
$data = file_get_contents($cache);
}
$xml = simplexml_load_string($data);

$html = '<ul>';
foreach($xml as $item)
{
$html .= '<li><a href="' . $item['href'] . '">' . $item['description'] . '</a> ' . $item['extended'] . '</li>';
}
$html .= '<li><a href="http://delicious.com/briancray">More of Brian Cray\'s delicious bookmarks…</a></li>';
$html .= '</ul>';
echo $html;
}

// display them
get_delicious();
?>
Source : http://briancray.com/2009/delicious-bookmarks-api-php/   
Comments

Comments are disabled for this post