院生エンジニアのにっき

  • Change style to Blue
  • Change style to Red
  • Change style to Green
  • Change style to Pink

Google AJAX Feed API   2007-07-30

今更なんですが、使ってみると便利ですね・・・

何が出来るかというと、

  • 簡単にクロスドメインのFeed(RSSやAtom)をJSON・XMLに変換してくれる
  • 試してないけどFeed Discovery機能によってURLからFeedを抜き出してくれる
  • Feed Controlといって、現在と記事の投稿時間の差を勝手に計算してくれたり、Feedをマージしてくれる(?)→http://www.google.com/uds/samples/feedapidocs/feedcontrol.html

元のサンプル(http://code.google.com/apis/ajaxfeeds/signup.html)だと、文字列だけしか表示してくれないんで、リンクになるよう簡単な変更をしてみました。


変更したサンプルにこのブログのRSSを投げてみると

となりました。。

Google先生、便利ですねぇ。

ちなみにサンプルコードを変更したのはこちら

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;>
  2.   <head>
  3.     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  4.     <title>Google AJAX Feed API - Simple Example</title>
  5.     <script type="text/javascript" src="http://www.google.com/jsapi?key=***"></script>
  6.     <script type="text/javascript">
  7.     google.load("feeds", "1");
  8.     function initialize() {
  9.       var feed_url = "Feed URL";
  10.       var feed = new google.feeds.Feed(feed_url);
  11.       feed.load(function(result){
  12.         if(!result.error){
  13.           var container = document.getElementById("feed");
  14.           for(var i = 0;i < result.feed.entries.length; i++){
  15.             var entry = result.feed.entries[i];
  16.             var div = document.createElement("div");
  17.             var anchor = document.createElement("a");
  18.             anchor.href = entry.link;
  19.             anchor.appendChild(document.createTextNode(entry.title));
  20.             div.appendChild(anchor);
  21.             container.appendChild(div);
  22.           }
  23.         }
  24.       });
  25.     }
  26.     google.setOnLoadCallback(initialize);
  27.     </script>
  28.   </head>
  29.   <body>
  30.     <div id="feed"></div>
  31.   </body>
  32. </html>

Feed URLを対象のURLに、keyはhttp://code.google.com/apis/ajaxfeeds/signup.htmlから取得して下さい。


コメントを書く