Skip to content

Instantly share code, notes, and snippets.

@psynewave
Created December 5, 2012 23:50
Show Gist options
  • Save psynewave/4220598 to your computer and use it in GitHub Desktop.
Save psynewave/4220598 to your computer and use it in GitHub Desktop.
// build the url from whatever data we already have on the page.
var feedsrc = "http://www.bayeast.org/frontpage/feed";
// Load the feeds api from google
google.load("feeds", "1");
// this function is run when google has loaded everything it needs using the setOnLoadCallback below
function GetFeed() {
// define the feed
var feed = new google.feeds.Feed(feedsrc);
// set how many entries we want to load
feed.setNumEntries(10);
// load the entries
feed.load(function(result) {
// if there were no errors, continue
if (!result.error) {
// loop through each entry in the feed
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
// Example output - this is where we start customizing the output
$('#feed').append('<div class="newsItem"><h2><a href="'+ entry.link +'" target="_blank">' + entry.title + '</a></h2>');
$('#feed').append(entry.contentSnippet + '</div>');
$('#feed').append('<hr>');
/* All data available for each entry:
[string] entry.title
[string] entry.author
[string] entry.publishedDate
[array] entry.categories
[string] entry.content
[string] entry.contentSnippet
[string] entry.link
*/
}
}
else {
console.log('error');
}
});
}
// once google has everything it needs, this will fire - we are
// telling it to run the GetFeed() function
google.setOnLoadCallback(GetFeed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment