網頁

2012年6月22日 星期五

Google Feed API

You can use the Google Feed JSON interface to write feed applications in any language that can handle a JSON-encoded result set with embedded status codes. 

將遠方的 RSS重新彙整到自己所開發的頁面。

CODE DEMO


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {

(function(jQuery){jQuery.extend({jGFeed:function(url,fnk,num,key){if(url==null){return false;}var gurl="http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+url;if(num!=null){gurl+="&num="+num;}if(key!=null){gurl+="&key="+key;}jQuery.getJSON(gurl,function(data){if(typeof fnk=="function"){fnk.call(this,data.responseData.feed);}else{return false;}});}});})(jQuery);

jQuery.jGFeed( 'http://www.lib.nthu.edu.tw/bulletin/RSS/rss_news.xml', function (feeds) {
if (!feeds) { return false; }
var lines = "<table width=100% border=0 cellspacing=0 cellpadding=0>" +
"<tr>" +
" <td width='25%' class='titletd'>日期</td>" +
" <td width='75%' class='titletd'>標題</td>" +
"</tr>";

for(var i=0; i<feeds.entries.length; i++){
var entry = feeds.entries[i];
var postDate = entry.publishedDate.substr(5,11);
if (entry.link) {
lines += "<tr><td class=titletd>" + postDate + "</td><td class=titletd><a href=\"" + entry.link + '"' + " target='_blank'>"+ entry.title + "</a></td></tr>";
}

}
lines += '</table>' // close table
jQuery('#newscontent').html(lines);

}, 10);

//mySpace();
});
</script>
<div id="newscontent">
</div>
<br><p class="promo_more"><a href="http://www.lib.nthu.edu.tw/bulletin/News_public/read_list_valid.php" target="_blank">More...</a></p>
</div>