Google AJAX Feed API - 使用Javascript 处理Atom/RSS

2008-02-25 23:11Update
TAGS: Google | Ajax | Feed | Atom | RSS

LifevV.COM编辑部

Google AJAX Feed API是由はGoogle提供的使用javascript聚合Atom/RSS的非常便利的Javascript库。

使用Google AJAX Feed API,你可以无需了解ATOM/RSS细节,只需要使用简单的Javascript代码,便可以在自己的WEB页面聚合任意来自本域名或其他域名的Atom/RSS文件。

Google AJAX Feed API的导入


使用Google AJAX Feed API,需要取得Google AJAX API key。
1)通过官方项目首页的 Sign-up for a Google AJAX API key [右上角]取得API key。
2)在API key的确认页面中:
Your key is:
ABQIAAAAgHl8cLhebGFDLkyUBREzsdfK1qjx1LamjcxxewrWsg2QhTgqJyLNlMl
XS2HB5g2XXXXyyyy

※API key

Here is an example web page to get you started:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google AJAX Feed API - Simple Example</title>
    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAgHl8cLhebGFDLkyUBREz_
BQXlJK1qjx1LamjcHc7zRDpWsg2QhTgqJyLNlMlXS2HB5g2zslK1xO37A">
    </script>
    <script type="text/javascript">
 
    google.load("feeds", "1");
 
    function initialize() {
      var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
      feed.load(function(result) {
        if (!result.error) {
          var container = document.getElementById("feed");
          for (var i = 0; i < result.feed.entries.length; i++) {
            var entry = result.feed.entries[i];
            var div = document.createElement("div");
            div.appendChild(document.createTextNode(entry.title));
            container.appendChild(div);
          }
        }
      });
    }
    google.setOnLoadCallback(initialize);
 
    </script>
  </head>
  <body>
    <div id="feed"></div>
  </body>
</html>

※Google AJAX Feed API使用范例


http://www.google.com/jsapi?key=ABQIAAAAgHl8cLhebGFDLkyUBREz_
BQXlJK1qjx1LamjcHc7zRDpWsg2QhTgqJyLNlMlXS2HB5g2zslK1xO37A
key参数设置为刚才取得的API key。

var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
google.feeds.Feed()构造方法的参数设置为具体的RSS URL。
比如:
var feed = new google.feeds.Feed("http://www.lifevv.com/index.rss");

如此便可,非常简单。当然,你还可以设置更加复杂的参数。具体请参考官方文档。

Google AJAX Feed API其它参考资料


Google AJAX Feed API项目首页
http://code.google.com/apis/ajaxfeeds/
Developer's Guide - Google AJAX Feed API - Google Code
Google AJAX Feed API - AJAX Tune Bar
  • Relative Articles
 
Copyright ©2006-2010 lifevv.com. All Rights Reserved
POWERED BY @pmplat.syboos.com