2011-05-15 101 views
0

我無法讓Google的加載Feed正常工作。實施例被認爲是在www.eslangel.comGoogle Feed API

我把這個代碼在頭

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

然後,只是爲了測試,我複製並使用一個Digg送入身體粘貼其樣本代碼我的博客,但沒有任何結果。

有沒有人知道我可能會做錯什麼?

/* 
* 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);​ 

回答

1

那麼,你是否也創建了飼料容器? :-)

試着將

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

飼料加載腳本之前。

+0

我最初並沒有在那裏放置一個容器,但現在它仍然不能工作。請參閱www.eslangel.com – Leahcim 2011-05-15 08:31:26

+0

檢查最後一行「google.setOnLoadCallback(OnLoad); ​」,最後嘗試刪除令人討厭的符號。 – spacevillain 2011-05-15 08:39:35

+0

謝謝,這就是問題所在 – Leahcim 2011-05-15 08:40:50