Created
May 31, 2011 18:33
-
-
Save LightGuard/1001030 to your computer and use it in GitHub Desktop.
Google Feed API usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W4C//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 Search API Sample</title> | |
<script src="http://www.google.com/jsapi" type="text/javascript"></script> | |
<script type="text/javascript"> | |
/* | |
* How to load a feed via the Feeds API. | |
*/ | |
google.load("feeds", "1"); | |
// Our callback function, for when a feed is loaded. | |
function feedLoaded(result) { | |
if (!result.error) { | |
// Grab the container we will put the results into | |
var container = document.getElementById("content"); | |
container.innerHTML = ''; | |
// Loop through the feeds, putting the titles onto the page. | |
// Check out the result object for a list of properties returned in each entry. | |
// http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON | |
for (var i = 0; i < result.feed.entries.length; i++) { | |
var entry = result.feed.entries[i]; | |
var div = document.createElement("div"); | |
div.className = "rss-entry"; | |
var titleDiv = document.createElement("div"); | |
titleDiv.className = "rss-entry-title"; | |
var entryLink = document.createElement("a"); | |
entryLink.href = entry.link; | |
entryLink.appendChild(document.createTextNode(entry.title)); | |
titleDiv.appendChild(entryLink); | |
var snippetDiv = document.createElement("div"); | |
snippetDiv.className = "rss-entry-snippet"; | |
snippetDiv.appendChild(document.createTextNode(entry.contentSnippet)); | |
div.appendChild(titleDiv); | |
div.appendChild(snippetDiv); | |
container.appendChild(div); | |
} | |
} | |
} | |
function OnLoad() { | |
// Create a feed instance that will grab Digg's feed. | |
var feed = new google.feeds.Feed("http://groups.diigo.com/group/cdi-tech-hub/rss"); | |
// Calling load sends the request off. It requires a callback function. | |
feed.load(feedLoaded); | |
} | |
google.setOnLoadCallback(OnLoad); | |
</script> | |
</head> | |
<body style="font-family: Arial;border: 0 none;"> | |
<div id="content">Loading...</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment