2012年3月25日 星期日

Plurk API 1.0 with libcurl (Linux)

Platform: Debian Squeeze

Requirement: libcurl4-openssl-dev

Get Plurk API Key: Goto  http://www.plurk.com/API/1.0/ to get an API key (Fill the form, and click "Issue API key")

Plurk.c: (need API_KEY/USERNAME/PASSWORD)
#include <stdio.h> #include <stdlib.h> #include <curl/curl.h> int main (int argc, char *argv[]) { char POST[256]; CURL *curl; curl = curl_easy_init (); sprintf (POST, "api_key=API_KEY&username=USERNAME&password=PASSWORD&no_data=1"); curl_easy_setopt (curl, CURLOPT_URL, "http://www.plurk.com/API/Users/login"); curl_easy_setopt (curl, CURLOPT_POSTFIELDS, POST); curl_easy_setopt (curl, CURLOPT_COOKIEFILE, "cookie.txt"); curl_easy_setopt (curl, CURLOPT_COOKIEJAR, "cookie.txt"); curl_easy_perform (curl); /* Perform Login */ sprintf (POST, "api_key=API_KEY&qualifier=says&lang=tr_ch&content=!FB %s", argv[1]); curl_easy_setopt (curl, CURLOPT_URL, "http://www.plurk.com/API/Timeline/plurkAdd"); curl_easy_setopt (curl, CURLOPT_POSTFIELDS, POST); curl_easy_setopt (curl, CURLOPT_COOKIEFILE, "cookie.txt"); curl_easy_setopt (curl, CURLOPT_COOKIEJAR, "cookie.txt"); curl_easy_perform (curl); /* Perform an Plurk messge and this message willnot send to Facebook */ curl_easy_cleanup (curl); return 0; }

Makefile:
all: Plurk.c gcc -o Plurk Plurk.c -lcurl

Usage
>> ./Plurk "Plurk API Test"

Finish

在Blogger中加入Source Code區塊

在HTML的POST中加入以下內容即可

.post code { display: block; font-family: Courier New; font-size: 10pt; margin:.75em 0; overflow: auto; background: #f0f0f0; border: 1px solid #c0c0c0; padding: 10px 10px 10px 10px; line-height: 1.0em; white-space: pre; }