gpt4 book ai didi

javascript - 使用 Google Feeds API (JavaScript) 获取 DeviantArt Media RSS

转载 作者:行者123 更新时间:2023-12-02 20:23:06 29 4
gpt4 key购买 nike

我正在尝试使用 Google 的 Feed API 从 DeviantArt 提供的 RSS feed 中获取媒体,并以 JSON 格式返回。提要如下:

http://backend.deviantart.com/rss.xml?type=deviation&q=boost%3Apopular%20tarutaru

Google 提供了很多示例,但涉及媒体源的示例很少,而涉及媒体源的示例都利用了媒体组。但看看我正在尝试阅读的这个特定提要,我没有看到任何媒体组。每个提要条目只有一个与其关联的“媒体”项。

<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>

我现在用来读取提要的代码是这样的,现在只是尝试读取 media:title 值,但我想读取所有 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);​

取自此处提供的示例:http://code.google.com/apis/ajax/playground/#load_feed

问题是,我不知道达到这些值的正确语法是什么,而且我已经尝试了几个小时,所以你现在是我唯一的希望。

任何帮助将不胜感激。这是我要做的东西,作为送给我兄弟的生日礼物,我想尽快摆脱这个麻烦,以便将礼物送达。 :)

提前谢谢您。

最佳答案

查找用于读取 XML 提要的示例(我手头没有 URL)。这就是我为了解决这个问题所做的:在调用 feed.load() 之前,我将格式设置为 XML:feed.setResultFormat(google.feeds.Feed.XML_FORMAT);然后,在回调中,我循环遍历提要中的项目(看起来您可以对您的项目执行相同的操作,因为它作为项目返回)

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;
}

这些应该按原样为您工作,因为您的提要也有标题和链接。按照相同的基本方案获取其余数据。

关于javascript - 使用 Google Feeds API (JavaScript) 获取 DeviantArt Media RSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12988675/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com