Coding, is? Fun!

Wednesday, September 24, 2008

What is OpenSocial?

The OpenSocial standard is currently at version 0.8. Already, it has been implemented by many social networking sites such as Friendster, Hi5 and Orkut. What does the standard mean?
In 2007, came out with an API and a platform for delivering widgets. A widget can be a word game, or a set of friends sharing movie reviews. Facebook followed a fairly complex model to render such widgets, and let them access facebook's social API.
But facebook widgets work only with facebook. They have to be basically rewritten to work with Orkut or other social sites.
Later in 2007, Google released the OpenSocial standard. That standard provides a spec for social networking sites (on the one hand) and widget writers (on the other) to implement. If sites Orkut and Friendster implement the OpenSocial standard, then a widget that works in Orkut will work with Friendster with no rewriting.
As with any standard, OpenSocial is based upon an abstraction of the services provided by a social network. Google also leveraged its existing Gadget spec (Google Gadgets) and added OpenSocial as a "feature" of gadgets.

Google Gadgets
Google gadgets are based upon the gadget spec. The gadget writer creates a gadget definition (which is in XML). This definition contains (among other things) Javascript code that can be called from the browser.
In a typical scenario, the gadget definition is written and is available in a public url -
The gadget container is the host that is going to display the gadget. That site can be When you hit the host page, it will send a request to the gadget server, passing in the url of the gadget xml (in this case, Google has a freely hosted gadget server called There is also an open source project called Shindig that provides the code for a gadget server. The gadget server does the heavy lifting of translating the gadget definition to HTML that can be rendered on the browser. Among other things, the gadget definition provides localized "message bundles" for getting localized strings. A gadget can ask for different "features" from the gadget server.

Thus Google gadgets can be run in your website, provided you have a gadget server available.

Open Social
Google built Open Social as one of the features of the gadget server.
In the google gadget example above, there are three servers involved - the gadget definition host,the gadget server and the gadget container. The gadget container, in social networks, is a social container. For example, the social container knows who the current user is, his profile information, who his friends are and what his activities are. Abstractly, these are modelled as a set of social API. The social container renders the gadget and then provides social API services to it.
Take the case of Orkut - Orkut contains social data about you. In its profile pages and canvas pages, it renders applications or "widgets" These widgets are rendered using as the gadget server. The widget definitions are hosted in different third party web servers.
Orkut provides its social API to the widget by exposing Javascript functions.
Because these Javascript functions and their namespaces are a OpenSocial standrad, the same widget can work in any OpenSocial compliant website, such as Hi5 or Friendster.

If you are writing a widget you should refer to the gadget spec and the open social spec. Let us say a sample widget allows you to send messages to all your friends in a particular network. That widget will call a OpenSocial API function to get the list of friends and show them to you. It will call a different OpenSocial API function to send messages to the friends' inbox. Both these functions are available via the Javascript API.

A sample gadget definition is below:
<xml version="1.0" encoding="UTF-8" >
<ModulePrefs title="List Friends Example>
<Require feature="opensocial-0.7"/>
<Content type="html>
<script type="text/javascript>
/** * Request for friend information. */ function getData() { var req = opensocial.newDataRequest(); req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), 'viewer'); req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS), 'viewerFriends'); req.send(onLoadFriends); };
/** * Parses the response to the friend information request and generates * html to list the friends along with their display name. * * @param {Object} dataResponse Friend information that was requested. */ function onLoadFriends(dataResponse) { var viewer = dataResponse.get('viewer').getData(); var html = 'Friends of ' + viewer.getDisplayName(); html += ':
    '; var viewerFriends = dataResponse.get('viewerFriends').getData(); viewerFriends.each(function(person) { html += '
  • ' + person.getDisplayName() + '
  • '; }); html += '
'; document.getElementById('message').innerHTML = html; };
<div id="message">

If you are a social network, and you want to implement OpenSocial, then you have to do the following:
- Download, install and run Shindig (there is a PHP and Java version). That will be your gadget server - you can, of course, implement your own gadget server, by going through the gadget and open social spec.
- Implement the Javascript API by making calls back to your social network database from the browser. Implement this in a library and have it included in your gadget rendering page
- Implement a set of hosting pages for the gadgets (typically using iframes) so that the request for the gadget goes through the gadget server.
- Implement an authorization scheme.
- Implement a set of pages for searching, adding and removing widgets from a user's profile.

In conclusion, OpenSocial is an abstraction of the social API of a container and the gadget rendering modules of any widget.



Post a Comment

<< Home