MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Where's my Data API?

Happy holidays for you who had time off, and happy work for you who didn't. Of course, for those of us who are developers we no doubt had a working holiday :). Such is life in the world of tech...

Where's my Data API? Where's my Activities API?

Just wanted to let you folks know that we're working hard on the Data and Activities portions of OpenSocial. A lot of forum participants have been asking about them, and we're quite eager to get them up for you.

Why aren't they here already? Well, MySpace is kind of huge, and MySpace profiles tend to be very public--especially profiles of popular bands and celebrities. That creates a lovely atmosphere for virality, because popular profiles tend to be loci of friendship clusters, thus minimizing the degrees of separation between users. Hopefully those popular profiles will pick up your app and make it go viral. If your app goes viral, there is much cause to celebrate. That celebration might be cut short if the app goes down due to load. Because of the rather large scale of MySpace, we need to make sure that our middle tier is ready to go--your app will potentially be utilized by millions of simultaneous users, so we want your data to be served smoothy and error free.

Speaking of virality, we're also working on the Activities API. It's quite challenging to make it both flexible and scalable. As soon as we have a good picture of how it will look, we'll give you examples so you can get started coding.

Yes, there's Sample Code!

What blog post would be complete without sample code? The below app, which I recommend that you paste into the Canvas section, issues quite a few requests (different person, friends, photos, and albums requests). It then dumps the response objects into HTML so you can look at the properties that are available to you. Pretty straightforward, but illuminatory if you're new to the OpenSocial development process. I won't do much explaining of the workings of the code--it's more of a cut and paste deal. If you want basic documentation, head over to the "Learn and Play" section.

Working App 1 : Request example and data dump app
<style> #output { overflow:scroll;height:100%; } .objectGraph { font-size:small; background-color:whitesmoke; margin:10px; padding:10px; border:solid; border-width:1px; } .arrayGraph { font-size:small; } pre { padding:20px; background-color:white; border:dashed; border-width:1px; } </style> <div id="output"></div> <script type="text/javascript"> function init() { //Set the owner id so we don't have to use it later var personId = opensocial.DataRequest.PersonId.OWNER; //Create our DataRequest object var dr = opensocial.newDataRequest(); //Set up an empty params object so we can use it for functions that require params. var opt_params = {}; //Request Albums var albumReq = dr.newFetchAlbumsRequest(personId,opt_params); //Request Person data var personReq = dr.newFetchPersonRequest(personId); //Request Friends var friendReq = dr.newFetchPeopleRequest(opensocial.DataRequest.Group.OWNER_FRIENDS); //Request Online Friends var onlineFriends_Params = {}; onlineFriends_Params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.ONLINE_FRIENDS; var onlineFriendsReq = dr.newFetchPeopleRequest(opensocial.DataRequest.Group.OWNER_FRIENDS,onlineFriends_Params); //Request First 5 Friends (using paging) var pagedFriends_Params = {}; pagedFriends_Params[opensocial.DataRequest.PeopleRequestFields.FIRST] = 1; pagedFriends_Params[opensocial.DataRequest.PeopleRequestFields.MAX] = 5; var pagedFriendsReq = dr.newFetchPeopleRequest(opensocial.DataRequest.Group.OWNER_FRIENDS,pagedFriends_Params); //Request Extended Person data var extendedPersonParams = {}; extendedPersonParams[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.ID,MyOpenSpace.Person.Field.ABOUT, MyOpenSpace.Person.Field.BOOKS]; var bigPersonReq = dr.newFetchPersonRequest(personId,extendedPersonParams); //Request Photos var photoReq = dr.newFetchPhotosRequest(personId,opt_params); //Add all the requests to the DataRequest dr.add(albumReq,'Albums'); dr.add(personReq,'SmallPerson'); dr.add(bigPersonReq,'ExtendedPerson'); dr.add(friendReq,'BasicFriends'); dr.add(onlineFriendsReq,'OnlineFriends'); dr.add(pagedFriendsReq,'PagedFriends'); dr.add(photoReq,'Photos'); writeToOutput("Requesting data..."); dr.send(response); } //Response callback... function response(data) { writeToOutput("Got response back"); var albums = data.get('Albums').getData(); var bigPerson = data.get('ExtendedPerson').getData(); var person = data.get('SmallPerson').getData(); var friends = data.get('BasicFriends').getData(); var onlineFriends = data.get('OnlineFriends').getData(); var pagedFriends = data.get('PagedFriends').getData(); var photos = data.get('Photos').getData(); dumpArray("Albums","album",albums); dumpObject("Person","person",person); dumpObject("Extended Person","person",bigPerson); dumpArray("Friends","friend",friends); dumpArray("Online Friends","friend",onlineFriends); dumpArray("Paged Friends","friend",pagedFriends); dumpArray("Photos","photo",photos); } //Takes an object and dumps it out, with some example code function spillTheBeans(name, input) { var docOutput = ""; var cOutput = ""; var out = ""; if(input.fields_ != null) { input = input.fields_; } for(var prop in input) { if(typeof(input[prop]) != "function") { docOutput += "<br /><b>" + prop + ":</b> " + input[prop]; cOutput += "var _" + prop + " = " + name + ".getField(\""+prop+"\")" + ";\n"; } } out += "<div class=\"objectGraph\">"; out += "<b>Properties of "+name+":</b><br />"; out += docOutput; out += "<br /><br /><b>Code to access:</b>"; out += "<pre>" + cOutput + "</pre>"; out += "</div>"; return out; } //Writes a response object's data and example code function dumpObject(name,smallname,obj) { var out = ""; out += "<div class=\"arrayGraph\">"; out += "<h2>Got response back: Object of type "+name + "</h2>"; out += spillTheBeans(smallname,obj.fields_); out += "</div>"; writeRaw(out); } //Writes a response array's data and example code function dumpArray(name,subname,obj) { var out = ""; out += "<div class=\"arrayGraph\">"; out += "<h2>Got response back: Array of "+name+" with " + obj.size() + " items</h2>"; var iterator = 1; obj.each(function(myObj) { out += "<h4>" + subname +" " + iterator +"</h4>"; iterator++; out += spillTheBeans(subname,myObj); }); out += "</div>"; writeRaw(out); } function writeToOutput(message) { document.getElementById("output").innerHTML += "<br />" + message; } function writeRaw(message) { document.getElementById("output").innerHTML += message; } init(); </script>
Published Feb 19 2008, 02:32 AM by Chris
Filed under:

Comments

 

Savarino said:

this is the sample i've been waiting for - thanks!

note, developers will need to format this code since copy/paste puts it all on one line and errors out.

February 19, 2008 8:59 AM
 

MesmoTV said:

Will rest versions of the data and activities API be available at the same time as the javascript versions?

February 19, 2008 11:37 AM
 

Jonathan said:

The javascript interface is fine for q&d apps (quizzes, games, pokes, etc.), but 'real' apps need the REST API ;-)

February 19, 2008 7:42 PM
 

Sebastian said:

I cant believe that it is this late in the game and there is still no information whatsoever on the virality-centric API.. This is really disappointing.. at least you could be honest about why there is no mention of even what the API "might" look like, instead of blaming it on apps that might not be able to handle the load..

are there privacy or anti-spamming measures that you guys are planning?

February 20, 2008 8:38 AM
 

Arshavir said:

re: persistence API

Is newUpdatePersonAppDataRequest implemented, and if not when will it be? Thanks.

February 20, 2008 10:50 AM
 

StephanieBamBam said:

Sebastian - we haven't set all the rules around how communications will work, so it's a little difficult to give any real details quite yet.

The main issue is just what you menation - privacy and anti-spamming. We want to put the best rules in place to prevent this...while still allowing "legit" application developers to be able to accomplish what they need to.

As soon as we have solid info, we will share....promise.

February 20, 2008 1:45 PM
 

Henry said:

Hmm, I took this sample, put it in Dreamweaver, and formatted it nicely.

Then I stripped out everything but the "SmallPerson" and "BigPerson" bits and their respective functions.

Ran it through the test console, and it shows nothing.

Anyone got this working?  I also attempted copy/pasting from Notepad to no avail.

February 21, 2008 7:06 AM
 

Dave said:

Hi StephanieBamBam, (I love the bambam!)

Regarding the Data API, please can you tell us the size quota per user, per app for the data persistence? Currently with Orkut it is a 10KB limit per user, per app and there are requests to increase it to 100KB.

If you can give an idea of the size restrictions for myspace I'd forever appreciate it :)  And even if the API is not ready it will allow me to decide whether to use it or not..

Thanks!

February 21, 2008 4:58 PM
 

Happiness said:

Today is Thursday, March 13, 2008. Is there Data API, yet?

March 13, 2008 12:42 PM
 

MyTestApp said:

RESTful API for activities and app data plz....

March 14, 2008 2:27 AM
 

Cagri² [www.kabuscobar.net/ms]® said:

.

March 21, 2008 6:51 PM
 

Im Probably Drunk Right Meow! said:

want to know how to copy and paste?

ill tell ya

copy the example code and go here

codepress.fermads.net/index.php

click the php editor button and paste, it pastes correctly there, then just re-copy and paste in canvas surface

works perfectly :)

August 10, 2008 12:30 PM