Google Feed API — Now with instant gratification
May 19th, 2010 | Published in Google Ajax API
One of Google's most popular APIs is our Feed API. This API is found all over the web, making any feed content available for developers to embed on their sites.
A problem with embedding content in this manner is that there's no good way to make sure that your visitors see the freshest data, regardless of how long they stay on your page. Of course, you could try polling (also known as the "are we there yet?" method), repeatedly reloading the feed to see if the content has changed. This technique is generally a waste of bandwidth and doesn't always result in very low latency.
Instead, we've got something better. I'm pleased to announce a preview of a brand new version of the Feed API, which includes push updates. With this new version, you'll be able to make the latest feed data available to your visitors - when it's available - without polling or requiring a page refresh. The best part is that this will work with any PubSubHubbub enabled feed.
Here's a short demonstration of what I'm talking about:
As the video shows, this new version works much like the older Feed API. But instead of loading the existing feed data, you actually subscribe to the feed, and your callback is executed any time new feed data comes in.
Let's see how this works. First, you must load the API (just like before, except now v2):
We want to encourage you to experiment and build innovative applications with this new API - but since we don't know how it will be used, we can't quite open the floodgates yet. Therefore, we're initially making it available on a sign-up basis. Please fill out this form, telling us a little about how you'd like to use this API, and we'll try to give you access as soon as possible. Also, please remember that this is a Code Labs version, and therefore it may change or be removed at any time.
After we get some data from this experimental period we'll be able to open it up to everyone. Once you've begun experimenting, be sure to stop by our support forum or IRC channel to share your creations with everyone. If you'd like to learn more about how this API works, our Google I/O session will be posted to YouTube soon.
Posted by: Brett Bavar, Software Engineer and Adam Feldman, Product Manager
A problem with embedding content in this manner is that there's no good way to make sure that your visitors see the freshest data, regardless of how long they stay on your page. Of course, you could try polling (also known as the "are we there yet?" method), repeatedly reloading the feed to see if the content has changed. This technique is generally a waste of bandwidth and doesn't always result in very low latency.
Instead, we've got something better. I'm pleased to announce a preview of a brand new version of the Feed API, which includes push updates. With this new version, you'll be able to make the latest feed data available to your visitors - when it's available - without polling or requiring a page refresh. The best part is that this will work with any PubSubHubbub enabled feed.
Here's a short demonstration of what I'm talking about:
As the video shows, this new version works much like the older Feed API. But instead of loading the existing feed data, you actually subscribe to the feed, and your callback is executed any time new feed data comes in.
Let's see how this works. First, you must load the API (just like before, except now v2):
google.load("feeds", "2");Now, subscribe to the feed you're interested in and give the callback to be executed:
var feed = new google.feed.push.Feed("example.com/atom.xml");And, finally, you need to write the callback method that is run every time there's an update. In this example, we just display each new entry title as it comes in:
feed.subscribe(myCallback);
function myCallback() {For a running example you can try out, check out the Code Playground.
var container = document.getElementById("feed");
for (var i = 0; i var div = document.createElement("div");
div.appendChild(document.createTextNode(result.feed.entries[i].title));
container.appendChild(div);
}
}
We want to encourage you to experiment and build innovative applications with this new API - but since we don't know how it will be used, we can't quite open the floodgates yet. Therefore, we're initially making it available on a sign-up basis. Please fill out this form, telling us a little about how you'd like to use this API, and we'll try to give you access as soon as possible. Also, please remember that this is a Code Labs version, and therefore it may change or be removed at any time.
After we get some data from this experimental period we'll be able to open it up to everyone. Once you've begun experimenting, be sure to stop by our support forum or IRC channel to share your creations with everyone. If you'd like to learn more about how this API works, our Google I/O session will be posted to YouTube soon.
Posted by: Brett Bavar, Software Engineer and Adam Feldman, Product Manager