30 July Fri, 2010

Base AJAX Codes and Examples

Combined JSON/XML Result Format
This example reproduces the output of the XML example above, but combines usage of the JSON result format and access to the XML DOM. We iterate over all of the elements in the feed using the JSON data structure returned by the AJAX Feed API, and we use the special xmlNode pointer in each JSON result to access the element in the XML DOM corresponding to that entry. We use that XML element and getElementsByTagNameNS to access the diggCount extension element, which gives us access to the number of votes for that Digg story.

var feed = new google.feeds.Feed(”http://www.digg.com/rss/index.xml”);feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);feed.load(function(result) { if (!result.error) { var container = document.getElementById(”feed”); for (var i = 0; i < result.feed.entries.length; i++) { var entry = result.feed.entries[i]; var votesElement = google.feeds.getElementsByTagNameNS(entry.xmlNode, “http://digg.com/docs/diggrss/”, “diggCount”)[0]; var votes = votesElement.firstChild.nodeValue; var div = document.createElement(”div”); div.appendChild(document.createTextNode(entry.title + ” (” + votes + “votes)”)); container.appendChild(div); } }});View example (jsonxml.html)

The FeedControlNew!
This example uses the higher level google.feeds.FeedControl class to display a collection of feeds. This class is similar to the AJAX Search API’s Search Control layer GSearchControl. This example creates a FeedControl class, adds two feeds into the class, and then tells the feed control to draw.

Loading

View example (feedcontrol.html)

Discovering FeedsNew!
These two examples use the global methods, google.feeds.findFeeds and google.feeds.lookupFeed, to discover feeds based on search terms and to lookup feeds associated with standard web pages.

The first sample uses the google.feeds.findFeeds to dynamically populate a FeedControl based on search terms.

Loading

View example (findfeeds.html)

The second sample uses the google.feeds.lookupFeed to get the feed associated with a public Flickr web page for a given user and then dynamically populate a slideshow.

Loading

View example (lookup.html)

API Details
Supported Feed Formats
The Google AJAX Feed API supports the following feed formats:

Atom 1.0
Atom 0.3
RSS 2.0
RSS 1.0
RSS 0.94
RSS 0.93
RSS 0.92
RSS 0.91
RSS 0.9
Discovering FeedsNew!
The Google AJAX Feed API now supports additional global methods, google.feeds.findFeeds and google.feeds.lookupFeed which can be used to search for relevant feeds and lookup the associated feed for an HTML based URL.

How Feeds are Crawled
The Google AJAX Feed API crawls feeds with Feedfetcher, which is also used for Google Reader and the Google personalized homepage. See the Google Webmaster Help Center for details on Feedfetcher.

Feed Crawl Frequency
As the Google AJAX Feed API uses Feedfetcher, feed data from the AJAX Feed API may not always be up to date. The Google feed crawler (”Feedfetcher”) retrieves feeds from most sites less than once every hour. Some frequently updated sites may be refreshed more often.

Cross-Browser XML Access
Microsoft Internet Explorer does not support DOM Level 2, which means that it does not support namespace-aware DOM functions like getElementsByTagNameNS. The Google AJAX Feed API includes a cross-browser implementation of getElementsByTagNameNS since it is a common requirement for sites consuming feeds. The API does not include implementations of any other DOM Level 2 methods at this time.

Flash and other Non-Javascript EnvironmentsNew!
For Flash developers, and those developers that have a need to access the AJAX Feed API from other Non-Javascript environments, the API exposes a simple RESTful interface. In all cases, the method supported is GET and the response format is a JSON encoded result with embedded status codes. Applications that use this interface must abide by all existing terms of use. An area to pay special attention to relates to correctly identifying yourself in your requests. Applications MUST always include a valid and accurate http referer header in their requests. In addition, we ask, but do not require, that each request contains a valid API Key. By providing a key, your application provides us with a secondary identification mechanism that is useful should we need to contact you in order to correct any problems.

The easiest way to start learning about this interface is to try it out… Using the command line tool curl or wget, execute the following command:

curl -e http://www.my-ajax-site.com
‘http://ajax.googleapis.com/ajax/services/feed/load?q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml&v=1.0′
This command performs a Feed Load (/ajax/services/feed/load), for the Digg.com feed (q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml). The response has a Content-Type of text/javascript; charset=utf-8. You can see from the response below that the responseData is identical to the properties described in the JSON Result Format documentation. See this table mapping methods to base URLS for details on how the various access methods described in the previous sections are made available through the REST API.

Pages: 1 2 3

Tags: , ,

  • PHP and MySQL 5

    Beginning PHP 5 and MySQL: From Novice to Professional offers a comprehensive introduction to two of the most popular open source technologies on the planet: the PHP scripting language and the MySQL database server.

    Read More | Postd by Ltm.ming
  • Base AJAX Codes and Examples

    Make your Web pages stand out above the noise with JavaScript and the expert instruction in this much-anticipated update to the bestselling JavaScript Bible.

    Read More | Postd by Ltm.ming
  • Mastering CSS with DW CS3

    Durch Integration von Datenbankanbindung und Skriptsprachen wird Dreamweaver CS 4 zum alltagstauglichen Werkzeug für die Erstellung einfacher Redaktionssysteme.

    Read More | Postd by Ltm.ming
  • Pro JavaScript Techniques

    Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites.

    Read More | Postd by Ltm.ming
  • MySQL 5.0 Certification Study Guide

    This book is a very comprehensive guide to what MySQL offers and can teach you. br / br /Would definitely recommend for anyone needing a great book about MySQL.

    Read More | Postd by Ltm.ming
fashion handbags wow gold Hermes Birkin Bags Knockoff bag air max 2010 chanel handbags cheap golf clubs