Plurk microblogging has become extremely popular lately. It is very innovative with its highly user-friendly interface and clever timeline functionality. Plurk also has great deal of tools to play around. Updating one’s status is not all. You can take a daily photo and invite your friends to update their statuses as well. Updating the status comes with a bunch of attributes, like colors, language and qualifier. Unfortunately Plurk strives for users as there are numerous other microblogging sites out there luring people to share their time. Fortunately Plurk recently introduced its long awaited API for developers. It’s now more than easy to update the daily status with a simple snippet of PHP code.
I have composed a short and very quick-and-dirty simple code to update the Plurk status. This code does nothing more than just sends a new plurk to user’s timeline. Adding a new entry requires logging onto the Plurk service. This will in turn require a free Plurk account to update. Using the API calls will require another free identifier, namely API key. You can obtain the key by visiting the API documentation page and filling out the request form. The comprehensive Plurk API allows developers create outstanding applications to complete more actions than mere status updates. The successful login will be temporarily stored as a cookie on the website and is used when calling services requiring authentication. The following code snippet can be beautified, but for simplicity I have included all the necessary steps in order to show the calls.
$path = dirname(__FILE__) . '/cookie_plurk';
$apiKey = 'your Plurk API key';
// login
$arr = array(
'username' => 'your Plurk account username',
'password' => 'your Plurk account password',
'api_key' => $apiKey
);
$s = curl_init();
curl_setopt($s, CURLOPT_URL,
'http://www.plurk.com/API/Users/login');
curl_setopt($s, CURLOPT_POST, true);
curl_setopt($s, CURLOPT_POSTFIELDS,
http_build_query($arr));
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($s, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($s, CURLOPT_USERAGENT,
'PHP Plurk API Agent');
curl_setopt($s, CURLOPT_COOKIEFILE, $path);
curl_setopt($s, CURLOPT_COOKIEJAR, $path);
$buffer = curl_exec($s);
curl_close($s);
// update
$arr = array(
'api_key' => $apiKey,
'qualifier' => 'says',
'content' => 'message to add to your timeline'
);
$s = curl_init();
curl_setopt($s, CURLOPT_URL,
'http://www.plurk.com/API/Timeline/plurkAdd');
curl_setopt($s, CURLOPT_POST, true);
curl_setopt($s, CURLOPT_POSTFIELDS,
http_build_query($arr));
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($s, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($s, CURLOPT_USERAGENT,
'PHP Plurk API Agent');
curl_setopt($s, CURLOPT_COOKIEFILE, $path);
curl_setopt($s, CURLOPT_COOKIEJAR, $path);
$buffer = curl_exec($s);
curl_close($s);
Plurk API returns JSON encoded data. This is easy to parse using PHP 5.0 json_decode function. You may also query your Plurk account as well as update your profile among many other services. While Plurk has been (and still is) one of the most wonderful microblogging services and the new API brings a completely new way to utilize it.