ワザワザこんなことをしなくてもGoogle Feed APIを使えばいいのだが、こんなことも出来るよ、程度の話で。
基本的なURLは以下の通り
http://www.google.com/reader/public/javascript/feed/[url]
これをjQueryのメソッドにしてみる。
Code
(function($){
$.gReaderFeed = function(url, options, fn){
var opt = $.extend({
n:10
}, options);
$.getJSON('http://www.google.com/reader/public/javascript/feed/' + url + '?callback=?', opt, fn);
}
})(jQuery);
Usage
気まぐれでjQueryを使わずに書いてみた。$.gReaderFeed('http://googleblog.blogspot.com/feeds/posts/default',
{'alt':'json'},
function ( data ){
var list = document.createElement('ul');
for (i in data.items) {
var item = data.items[i];
var post = document.createElement('li');
var link = document.createElement('a');
link.appendChild(document.createTextNode(item.title));
link.href = item.alternate.href;
post.appendChild(link);
var timestamp = document.createElement('span');
timestamp.appendChild(document.createTextNode(' - ' +
(function( date ){
return date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日';
})(new Date(item.published * 1000))));
post.appendChild(timestamp);
list.appendChild(post);
}
document.body.appendChild(list);
});
どんな引数があるか調べてみないと分からないが、多分資料は出てこないだろう。




0 Comments:
コメントを投稿