Dev Insights: MySpace Apps on a Tight Timeline |
|
Filed under: dev — ayn @ April 23, 2008
[Editor’s note: This is the first in a series of developer blog posts sharing some of our technical insights. Enjoy the jargon!] One of our clients needed an app for MySpace and also wanted it to be ready as one of the launch apps when MySpace launched their platform. I’ve compiled together some of the implementation gotchas we experienced along the way. Platform Overview MySpace has their own REST API that exposes their social network to app developers, there is an Open Social JavaScript layer that maps the MySpace REST API to the Open Social API. Initially, MySpace hosted all their apps for you. An app can be either a mixture of HTML and JavaScript inside an IFRAME, or a self-contained Flash SWF file. The MySpace Developer site has web forms for developers to copy and paste codes and submit them to MySpace. They now support an XML manifest like the other OpenSocial containers and Google Gadgets. An application has to go through a review process before going live, and revision of the hosted code have to be re-approved by MySpace subsequently. The only way for an app to contact an outside server is through the OpenSocial makeRequest() call, it takes a URI and some parameters, and it can make an OAuth-signed request to the URI. This is the mechanism I used to communicate between our server logic written in Ruby on Rails and the MySpace app. You can return JSON responses or plain HTML and render the outputs in JavaScript. The following is an example of a makeRequest call and its callback:
function new_user_check() {
try {
params = { METHOD : 'GET', AUTHORIZATION : gadgets.io.AuthorizationType.SIGNED };
gadgets.io.makeRequest( "http://HOST/myspace/is_new_user", function (json_data) { proc_new_user_check(gadgets.json.parse(json_data.text)); },
params )
trace(er.message); } }
if (data.new_user == "no") {
show_spinner(data.spin_controls_html); } else if (data.new_user == "yes") {
$("div#first_timer").fadeIn("slow");
} else { //non-owner viewing canvas
$("div#non_owner").show();
} }
The MySpace apps guidelines define what developers are allowed to do inside an application. Eventually, they will turn on Caja to sanitize all JavaScript and HTML tags inside the app. Most of the popular apps now violate multiple items in guidelines to get around the lack of viral features in MySpace. We played it safe and actually followed the guidelines. For example, we are not allowed to put any links on the home and profile surfaces, the only official way to navigate out of those surfaces is to use the requestNavigateTo() call. Though plenty of apps have regular hyperlinks that bypasses this restriction. Also we are not allowed to embed Flash using the <OBJECT> tag or pass in flash params, instead they prefer a self-contain Flash SWF (uploaded to MySpace) that uses the MySpace REST API.
What I found very interesting is that the JSON responses from makeRequest() are encoded differently depending on which surface you’re on. On the canvas surface, the JSON response is stored inside a “text” field of the returned object, and you have to parse that back to another JSON object (see code above), but on the other 2 surfaces, the object returned is just a plain JSON object without the “text” field.
MySpace apps work a lot differently than Faebook and Bebo. There is potential for new types of features as all 3 surfaces can work together to bring a brand new experience to the users. It is a shame that there aren’t very many features in the platform right now for the apps to grow virally. It will be interesting to see how the platform evolve and also to check out other implementation of applications with OpenSocial. |