6.A Jaiku API

Jaiku原本是一家在芬蘭的公司,因為其類似微型部落格的功能以及在Web與行動手機運用上的便利性,被Google看上,並於2007年10月9日被Google收購。

我想,Jaiku的賣點在於他能讓行動用戶隨時隨地都能上網發訊息報告自己的動態,以及觀察朋友們的動向,當初芬蘭會有這服務也是因為手機在他們國家的普及性(Nokia大廠耶!),可以用手機發簡訊買投幣式飲料、開公共廁所的門、付停車費、買電車票等等好玩又有趣的應用,甚至可以發簡訊和電視上的Live節目做互動式聊天呢,我想芬蘭人一定不斷地在想手機服務還可以做什麼加值應用,因此促成了Jaiku這個"移動微型部落格"的產生吧。

類似這種微型部落格還有BUBOO和Twitter等,也都有不少人使用。各國的公司也逐漸看上這種延伸至手機上的SMS簡訊服務或其他應用,像最近工研院辦的無線粉絲大帝國也是為了提倡行動加值服務,從學生團體中找尋創意,創造更多行動服務的可能。

接下來介紹一下Jaiku提供的一些API
Jaiku提供了兩種介面來閱讀和發表Jaiku的訊息,分別是XML-RPC和JSON,而我們要使用時,需要一組驗證碼,每個使用者都有一組Jaiku的API key,是用來辨別你的身分,登入Jaiku後在http://api.jaiku.com 就可看到。

*在POST request中加上這段,用來驗證使用者。

?user=$user&personal_key=$personal_key


*若是使用JSON,在傳送POST request時須先呼叫
api.jaiku.com/json
並且加入驗證參數(將user和personal_key設定為自己的)
POST /json
user=jaiku&personal_key=12345678901234&method=test&echo=Hello

這時會收到一response
{"status": "ok", "echo": "Hello"}


*而要自行增加RSS訂閱時,加上
http://jaiku.com/feed/rss
http://devku.jaiku.com/feed/rss

和訂閱user及API Key
http://devku.jaiku.com/feed/rss?user=[Your nick]&personal_key=[Your key]
http://devku.jaiku.com/contacts/feed/rss?user=[Your nick]&personal_key=[Your key]

 

*接下來的小範例可以擷取你所要的JSON格式的channel資料

var url = "http://jaiku.com/channel/PeopleMountainPeopleSea/feed/json";

擷取到的資料如:

{ "title" : "Jaiku | Latest from #PeopleMountainPeopleSea", "url": "http:\/\/jaiku.com\/channel\/PeopleMountainPeopleSea", "stream": [ { "id": "49110784", "title": "\u53f0\u7063\u771f\u597d\u73a9", "content": "", "icon": "http:\/\/jaiku.com\/images\/icons\/web-camera.gif", "url": "http:\/\/jaiku.com\/channel\/PeopleMountainPeopleSea\/presence\/49110784", "created_at": "2008-11-17T17:37:44 GMT", "created_at_relative": "4 weeks, 1 day ago", "comments": "0", "user": { "avatar": "http:\/\/jaiku.com\/image\/avatar_default_t.jpg", "first_name": "Null", "last_name": "Web", "nick": "nullweb", "url": "http:\/\/nullweb.jaiku.com" } }, { "id": "49092882", "title": "\u5927\u5bb6\u4f86\u53bb\u904a\u53f0\u7063", "content": "", "icon": "", "url": "http:\/\/jaiku.com\/channel\/PeopleMountainPeopleSea\/presence\/49092882", "created_at": "2008-11-17T11:28:27 GMT", "created_at_relative": "1 month ago", "comments": "0", "user": { "avatar": "http:\/\/jaiku.com\/image\/avatar_default_t.jpg", "first_name": "Ronnie", "last_name": "Lee", "nick": "RonnieLee", "url": "http:\/\/RonnieLee.jaiku.com" } }, { "id": "49092551", "title": "\u5e79 ,\u4f60\u7238\u570b\u5bf6\u5167", "content": "", "icon": "", "url": "http:\/\/jaiku.com\/channel\/PeopleMountainPeopleSea\/presence\/49092551", "created_at": "2008-11-17T11:23:22 GMT", "created_at_relative": "1 month ago", "comments": "0", "user": { "avatar": "http:\/\/jaiku.com\/image\/avatar_default_t.jpg", "first_name": "Ronnie", "last_name": "Lee", "nick": "RonnieLee", "url": "http:\/\/RonnieLee.jaiku.com" } }, { "id": "49092547", "title": "\u5e79,\u4f60\u7238\u570b\u5bf6\u5167", "content": "", "icon": "", "url": "http:\/\/jaiku.com\/channel\/PeopleMountainPeopleSea\/presence\/49092547", "created_at": "2008-11-17T11:23:02 GMT", "created_at_relative": "1 month ago", "comments": "0", "user": { "avatar": "http:\/\/jaiku.com\/image\/avatar_default_t.jpg", "first_name": "Ronnie", "last_name": "Lee", "nick": "RonnieLee", "url": "http:\/\/RonnieLee.jaiku.com" } }, { "id": "49092546", "title": "\u8302\u4f2f,\u52a0\u6cb9\u963f", "content": "", "icon": "", "url": "http:\/\/jaiku.com\/channel\/PeopleMountainPeopleSea\/presence\/49092546", "created_at": "2008-11-17T11:22:46 GMT", "created_at_relative": "1 month ago", "comments": "0", "user": { "avatar": "http:\/\/jaiku.com\/image\/avatar_default_t.jpg", "first_name": "Ronnie", "last_name": "Lee", "nick": "RonnieLee", "url": "http:\/\/RonnieLee.jaiku.com" } } }

由這些抓出來的資料就可以找出一個規律性

id-文章的代碼

nick-發表人的暱稱

title-發表的內容

created_at -發表的時間

再以javascript以迴圈的方式讀出來

a function load(){
var head = document.getElementsByTagName("head")[0];
script = document.createElement("script");
script.type = "text/javascript";
script.src = url + "?callback=show";
head.appendChild(script);
}
function show(json) {
var c = document.getElementById("jaikus");
var uls = c.getElementsByTagName("ul");
if (!uls.length)
var ul = document.createElement("ul");
else
var ul = uls[0];
for (var i=json.stream.length-1; i >= 0; i--) {
var entry = json.stream[i];
var id = "jaiku-" + entry.id;
if (!document.getElementById(id)) {
var li = document.createElement("p");
li.id = id;
// User
var user = document.createElement("h3");
user.appendChild(document.createTextNode(entry.user.nick));
// Entry link & title
var post = document.createElement("a");
post.setAttribute('href', entry.url);
post.appendChild(document.createTextNode(entry.title));
//time
var time = document.createElement("p");
time.appendChild(document.createTextNode(entry.created_at));
li.appendChild(user);
li.appendChild(document.createElement("p"));
li.appendChild(post);
li.appendChild(time);
li.appendChild(document.createTextNode("------------------------------------------------"));
ul.insertBefore(li, ul.firstChild);
}
}
c.appendChild(ul);
}
window.onload = load;
setInterval( load, 1000 * 30);

var c = document.getElementById("jaikus");

" "裡面的參數要設為將呈現內容的div名稱

 

參考資料:

1.Jaiku Developer Documentation

http://devku.appspot.com/docs/api_doc

2.維基百科

http://zh.wikipedia.org/w/index.php?title=Jaiku&variant=zh-tw