Fetching DeviantArt Media RSS with Google Feeds API (JavaScript)

2.4k views Asked by At

I'm trying to use Google's Feed API to fetch the media from an RSS feed provided by DeviantArt, returned in JSON format. The feed is the following:

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

Google offers many examples, but few that involve media feeds, and those that do, all make use of media groups. But looking at this particular feed I am trying to read, I don't see any media groups. Each feed entry has only one "media" item associated with it.

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

The code I am using to read the feed right now is this, trying just to read the media:title value for now, but I would like to read all of the media: data.

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

Taken from the example provided here: http://code.google.com/apis/ajax/playground/#load_feed

The thing is, I have no idea what's the right syntax to reach these values, and I've been trying for hours, so you're my only hope right now.

Any help will be greatly appreciated. This is for something I'm making as a birthday present for my brother, and I want to get past this nuisance as soon as possible, so that the present will be delivered. :)

Thank you in advance.

1

There are 1 answers

0
Brian Pipa On

Look for the samples for reading an XML feed (I don't have the URL handy) . That's what I did to figure this out: I am setting the format to XML before I call feed.load(): feed.setResultFormat(google.feeds.Feed.XML_FORMAT); then, in the callback, I loop through the items in the feed (looks like you could do the same thing with yours since it is returned as items)

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

those should work as-is for you since your feed also has title and link. Follow the same basic scheme to get to the rest of the data.