少年幃禿的煩惱


心情也微微的...凸

最近的學習心得 都改放到 少年幃禿的煩惱@Google Sites

2008/07/17

Google AJAX Feed API (5) - Discovering Feeds

這兩個範例使用 global 方法, google.feeds.findFeedsgoogle.feeds.lookupFeed.

首先使用 google.feeds.findFeeds 來搜尋將結果動態的顯示在 FeedControl. Code:

&lt;html> &lt;head> <script type="text/javascript" src="//www.google.com/jsapi?key=YOUR-KEY"></script> <script type="text/javascript"> google.load("feeds", "1"); var defaultQuery = 'Official Google Blogs'; function findFeeds(query) { google.feeds.findFeeds(query, feedSearchDone); } function feedSearchDone(result) { var el = document.getElementById('feedControl'); if (result.error || result.entries.length <= 0) { el.innerHTML = 'No Results Found'; return; } // Create a feed control var feedControl = new google.feeds.FeedControl(); // Grab top 4.. for (var i = 0; i < 4; i++) { feedControl.addFeed(result.entries[i].url, result.entries[i].title); } feedControl.setLinkTarget(google.feeds.LINK_TARGET_BLANK); feedControl.setNumEntries(2); feedControl.draw(el); } google.setOnLoadCallback(function() {findFeeds(defaultQuery)}); </script> &lt;/head> &lt;body> <div id="feedControl">Loading</div> &lt;/body> &lt;/html> Demo:
Loading
第二個範例使用 google.feeds.lookupFeed, 輸入 Flickr 帳號, 然後動態的展示該帳號的照片.
Code: &lt;html> &lt;head> <script type="text/javascript" src="//www.google.com/jsapi?key=YOUR-KEY"></script> <script src="//www.google.com/uds/solutions/slideshow/gfslideshow.js" type="text/javascript"></script> <script type="text/javascript"> google.load("feeds", "1"); var defaultUser = 'dlc0421'; function newSlideShow(user) { showStatus('Resolving feed for ' + user); var url = 'http://www.flickr.com/photos/' + user; google.feeds.lookupFeed(url, lookupDone); } function lookupDone(result) { if (result.error || result.url == null) { showStatus('Could not locate feed for user'); return; } showStatus('Found Photo Feed'); // We need to switch over from Atom to RSS to get Yahoo Media for slideshow.. var url = result.url.replace('format=atom', 'format=rss_200'); showSlideShow(url); } function showSlideShow(url) { var options = { displayTime: 2500, transistionTime: 800, scaleImages: true, thumbnailTag: 'content', linkTarget : google.feeds.LINK_TARGET_BLANK }; new GFslideShow(url, "slideshow", options); } function showStatus(msg) { var ss = document.getElementById("feeds-5-div-2"); ss.innerHTML = '<div class=\"feed-loading\">' + msg + '</div>'; } google.setOnLoadCallback(function() {newSlideShow(defaultUser)}); </script> &lt;/head> &lt;body> <div id="slideshow">Loading</div> &lt;/body> &lt;/html> Demo:
Loading
^^^^^^^^^^^^現在有問題 不過 GFW 也把 Flickr 擋掉了, 我改天再修理.