It’s been a while since I’ve said anything on here – been busy!! First a bit of background on SocialGO for the uninitiated…
SocialGO is a social networking platform that allows anyone to create their own social networking site. Like many social-media orientated sites (like Facebook, Twitter, Flickr etc), SocialGO has its own API that allows a site owner to access the data on their site, add functionality to it and do all kinds of fancy things (I like to keep this site jargon-free, ha
)
Think about all of those applications you’ve seen on Facebook. Well, all of those are created using Facebook’s API. Without an API these applications would be completely standalone on the site without any type of integration with member profiles and the information on them – it’s exactly the same with the SocialGO API.
Getting the data from the SocialGO site database…
One of the fancy things that the SocialGO API lets you do is output a list of the various types of media available on the site. You can get the information and URLs for all of the images, videos and audio on the site. To do this you need to have a copy of the latest SocialGO API Class, a text editor and a server run the PHP.
The following code will output a list of photos from my SocialGO site:
<?php
include 'SNM_api.php';
$api = new SNM_api();
$api->setApiServer('http://api.socialgo.com/');
$api->setNetworkKey('----');
$api->setDeveloperKey('----');
$filter = array(
'album_id' => '7',
);
$result = $api->getPhoto($filter);
print "<?xml version=\"1.0\"?>\n";
print "<photolist>\n";
foreach ($result->media_item as $photo)
{
print " <url>$photo->absolute_uri</url>\n";
}
print "</photolist>\n";
?>
This code is run on my server, so if you visit – http://glidepro.net/wii-sg-site/db-test2.php – then you will see a list of all the images on my SocialGO site (http://wiidev.info). View the source-code of this page and you will see that the output has been formatted in XML thus…
<?xml version="1.0"?> <photolist> <url>http://static.socialgo.com/cache/61355/image/159.jpg</url> <url>http://static.socialgo.com/cache/61355/image/160.jpg</url> <url>http://static.socialgo.com/cache/61355/image/161.jpg</url> <url>http://static.socialgo.com/cache/61355/image/162.jpg</url>
…and so on!
…of course, you don’t have to output to XML, but I wanted to use this data with Flash/Actionscript3 – which has a comprehensive set of classes for loading and manipulating XML data.
Using the data…
OK, now I have my data all nicely formatted in XML, I can call this PHP file directly from Flash thus:
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("getphotos.php"));
function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
}
Ta-da! That was nice and simple, so step by step:
1. Define the variable to load the XML file and the XML object that will hold the XML data once it has been loaded
2. Load the PHP file.
3. Once the PHP has loaded, an event listener will fire and the XML data will be place in the XML object variable
4. Now it’s possible to get to any of the XML data by simply referring to the nodes. Take the XML I pasted above. Suppose I wanted to get the URL of the first photo, I’d output it like this:
trace (xmlData.url[0]);
Easy! Thanks to the wonders of AS3, you can use the actual XML node names. Back in the murky days of AS2 you would have needed to use something like this…
trace (xmlData.childNode[0]);
…which is completely meaningless to be perfectly honest! Logical, yet meaningless…
The Final Result!
OK, well I’ve skipped the step of writing the Actionscript, however
The example I created was a 3D spinning cube that displays 6 random photos from the SocialGO site. Simply put, the application finds out how many photo URLs are listed in the XML object and selects 6 random photos to put on each side of the cube.
Hit F5 to refresh and see different photos!
Check out http://glidepro.net/wii-sg-site/cube_finished.swf to see the SWF in a new window – might be easier when refreshing…
Well, that’s all for the time being, but there’s loads more to come!
Over n out…
- BROWSE / IN TIMELINE
- « Update of my projects…
- » I heart MySuiteStuff!
- BROWSE / IN API SocialGO
SPEAK / ADD YOUR COMMENT
Comments are moderated.

