Ning’s Atom API
I spent a bit of time last week playing with Ning’s new Atom API. Call me biased, but I think it’s sensational. It’s available for every app on Ning, and it allows you to browse content and tags, pull information about applications and users, and lets you explore the genealogy of apps within the Ning playground.
I started with Confess, and grabbed a raw xml packet of all of the clones that have been made of it (89 so far, not bad!) since Ning launched: http://confess.ning.com/xn/atom/1.0/application/children
The next thing I wanted to do was request some of the anonymous confessions from Confess and list them out. I did this in PHP using Curl and simpleXML. You can see the results (and also grab the code) here. If you have a look at the raw xml, you can see that there are almost 700 confessions in the content store, and yes, they’re anonymous.
Confess has a thumbs up and thumbs down feature that lets you rate confessions; after receiving too many thumbs down in relation to thumbs up, a confession is automatically deleted from the content store. I wanted to alter my list visually to reflect the popularity of each confession. This meant bumbling around with simpleXML for a while to discover how it supports namespaces. Ning objects have a few built-in attributes, like title, description etc; any additional attributes that a developer uses show up in the my: namespace, so I needed to point simpleXML at the values for my:thumbsup and my:thumbsdown. This turned out to be pretty simple. When you iterate over each entry in the list of objects, you can dump all of the my variables into an array, like this:
foreach ($xml->entry as $entry) {
$my = $entry->children(’http://confess.ning.com/xn/atom/1.0′);
from there you can access them via an index, like $my[0], $my[1] etc. I was vaugely surprised that I couldn’t access them as named properties, so if I’m doing something backwards there, please let me know.
Here’s the result (and the code) anyway. I kept noodling, and collected all of the words from all of the confessions into an array based on frequency; I removed some commonly used words like ‘a’ and ‘the’, and then I tossed the array at Ning’s built in function for generating tag maps so that I could see the keyword frequency visually. Then I wired up each keyword to an ajax function which pulls related photos from flickr. You can see the final bit of code here. It works pretty nicely, but the calls to flickr only work in Firefox unfortunately because of the way I put the javascript together. If you’re not using Firefox, you can get a little preview here:

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically each day to your feed reader.
Hey, Phil. I have found SimpleXML’s namespace support to be somewhat annoying when working with Atom feeds. I usually end up using DOM and XPath to get what I want. After creating the DomDocument, create a DomXPath object and then register the three relevant namespaces (’atom’ for the root xmlns, ‘xn’, and ‘my’) and then you can use handy xpath queries such as:
foreach ($xpath->query(’/atom:feed/atom:entry’) as $entry) {
$myAttrs = $xpath->query(’my:*’, $entry);
foreach ($myAttrs as $attr) {
// $attr is a DomNode
}
}
Confessions are very interesting and I enjoyed reading them. Good idea.