开发者

Google Feed API

开发者 https://www.devze.com 2023-03-05 19:14 出处:网络
I\'m having trouble getting Google\'s load feed to work. Example is supposed to be at www.eslangel.com

I'm having trouble getting Google's load feed to work. Example is supposed to be at www.eslangel.com

I put this code in the header

<script type="text/javascript" 
src="https://www.google.com/jsapi?key=ABQIAAAAO2BkRpn5CP_ch4HtkkOcrhQRKBUhIk5KoCHRT6uc9AuUs_-7BhRyoJdFuwAeeqxoUV6mD6bRDZLjSw">
</script>

And then, ju开发者_如何学JAVAst to test, I copied and pasted their sample code using a Digg feed into the body of my blog, but there's no result of any kind.

Does anyone have any idea what I might be doing wrong?

/*
*  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.appendChild(document.createTextNode(entry.title));
      container.appendChild(div);
    }
  }
}

function OnLoad() {
  // Create a feed instance that will grab Digg's feed.
  var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");

  // Calling load sends the request off.  It requires a callback function.
  feed.load(feedLoaded);
}

google.setOnLoadCallback(OnLoad);​


Well, did you also create a container for the feed? :-)

Try placing

<div id="content"></div>

before the feed loading script.

0

精彩评论

暂无评论...
验证码 换一张
取 消