使用Google Feeds API(JavaScript)获取DeviceArt媒体RSS
我正在尝试使用Google的FeedAPI从DeviantArt提供的RSS提要获取媒体,该RSS提要以JSON格式返回。提要如下所示: 谷歌提供了很多例子,但很少有涉及媒体提要的,而且那些涉及媒体提要的,都是利用媒体集团。但是看看我正在阅读的这个特别的提要,我没有看到任何媒体群。每个提要条目只有一个与之关联的“媒体”项使用Google Feeds API(JavaScript)获取DeviceArt媒体RSS,javascript,rss,media,google-feed-api,mediarss,Javascript,Rss,Media,Google Feed Api,Mediarss,我正在尝试使用Google的FeedAPI从DeviantArt提供的RSS提要获取媒体,该RSS提要以JSON格式返回。提要如下所示: 谷歌提供了很多例子,但很少有涉及媒体提要的,而且那些涉及媒体提要的,都是利用媒体集团。但是看看我正在阅读的这个特别的提要,我没有看到任何媒体群。每个提要条目只有一个与之关联的“媒体”项 <item> <title>Expectant Tarutaru</title> <link>http://requiem-s
<item>
<title>Expectant Tarutaru</title>
<link>http://requiem-shade.deviantart.com/art/Expectant-Tarutaru-38312114</link>
<guid isPermaLink="true">http://requiem-shade.deviantart.com/art/Expectant-Tarutaru-38312114</guid>
<pubDate>Sat, 19 Aug 2006 17:20:08 PDT</pubDate>
<media:title type="plain">Expectant Tarutaru</media:title>
<media:keywords/>
<media:rating>nonadult</media:rating>
<media:category label="Games">fanart/traditional/drawings/games</media:category>
<media:credit role="author" scheme="urn:ebu">Requiem-Shade</media:credit>
<media:credit role="author" scheme="urn:ebu">http://a.deviantart.net/avatars/r/e/requiem-shade.jpg</media:credit>
<media:copyright url="http://requiem-shade.deviantart.com">Copyright 2006-2012 !Requiem-Shade</media:copyright>
<media:description type="html"><![CDATA[ A pregnant Tarutaru White Mage. Was a request from another board. Yes, I took liberties with Square-Enix's original design. Yes, Tarutaru look like that as adults, except the females are flat-chested. Had to augment her form to reflect the development of her body as her children grow inside her. ]]></media:description>
<media:thumbnail url="http://th06.deviantart.net/fs11/150/i/2006/231/c/f/Expectant_Tarutaru_by_Requiem_Shade.jpg" height="150" width="140"/>
<media:thumbnail url="http://th03.deviantart.net/fs11/300W/i/2006/231/c/f/Expectant_Tarutaru_by_Requiem_Shade.jpg" height="322" width="300"/>
<media:content url="http://fc06.deviantart.net/fs11/i/2006/231/c/f/Expectant_Tarutaru_by_Requiem_Shade.jpg" height="463" width="431" medium="image"/>
<media:content url="http://www.deviantart.com/download/38312114/" medium="document"/>
<description><![CDATA[ A pregnant Tarutaru White Mage. Was a request from another board. Yes, I took liberties with Square-Enix's original design. Yes, Tarutaru look like that as adults, except the females are flat-chested. Had to augment her form to reflect the development of her body as her children grow inside her.<br /><div><img src="http://th03.deviantart.net/fs11/300W/i/2006/231/c/f/Expectant_Tarutaru_by_Requiem_Shade.jpg" alt="thumbnail" /></div> ]]></description>
</item>
取自此处提供的示例:
问题是,我不知道达到这些值的正确语法是什么,我已经尝试了几个小时,所以你是我现在唯一的希望
任何帮助都将不胜感激。这是我为我哥哥做的生日礼物,我想尽快克服这个麻烦,这样礼物就能送到了。:)
提前谢谢。查找用于阅读XML提要的示例(我手边没有URL)。我就是这么想的: 在调用feed.load()之前,我将格式设置为XML: setResultFormat(google.feeds.feed.XML_格式); 然后,在回调中,我循环遍历提要中的项(看起来您可以对自己的项执行相同的操作,因为它是作为项返回的)
功能feedLoaded(结果){
如果(!result.error){
//将所有项目退回。
var items=result.xmlDocument.getElementsByTagName('item');
//循环浏览我们的项目
对于(变量i=0;i
因为你的订阅源也有标题和链接,所以这些应该对你起作用。按照相同的基本方案获取其余的数据。你有没有尝试过类似于
entry的方法。
和标签名,如div.appendChild(document.createTextNode(entry.title+entry.pubDate+entry.link+entry.media))
等。条目
部分是整个项目
,我想您可以在创建文本节点之前,通过解析条目。媒体
项目来获取媒体:标题
。。。
/*
* 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.mediaTitle));
container.appendChild(div);
}
}
}
function OnLoad() {
// Create a feed instance that will grab Digg's feed.
var feed = new google.feeds.Feed("http://backend.deviantart.com/rss.xml?type=deviation&q=boost%3Apopular%20tarutaru");
// Calling load sends the request off. It requires a callback function.
feed.load(feedLoaded);
}
google.setOnLoadCallback(OnLoad);
function feedLoaded(result) {
if (!result.error) {
// Get all items returned.
var items = result.xmlDocument.getElementsByTagName('item');
// Loop through our items
for (var i = 0; i < items.length; i++) {
var item = items[i];
// Get the data from the element. firstChild is the text node containing
// the title, and nodeValue returns the value of it.
var title = item.getElementsByTagName('title')[0].firstChild.nodeValue;
var link = item.getElementsByTagName('link')[0].firstChild.nodeValue;
}