Google's OpenSocial platform allows developers to write applications once that can run across multiple social networks. OpenSocial provides common APIs for accessing user data like friends lists and storing application data. Developers can use the People and Relationships, Persistence, and Activities APIs to build applications that will work across networks implementing OpenSocial like Google+, Orkut, and Ning.
12. 2. Importing Open Social
<ModulePrefs title=quot;Title of Your Applicationquot;>
<Require feature=quot;opensocial-0.5quot;/>
</ModulePrefs>
13. 3. Using Open Social
function onLoadFriends(dataResponse) { // do something with the
dataResponse }
/**
* Request for friend information when the page loads.
*/
function getData() {
document.getElementById('message').innerHTML = 'Requesting friends...';
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
req.add(req.newFetchPeopleRequest ('VIEWER_FRIENDS'), 'viewerFriends');
req.send(onLoadFriends);
};
14. 3. Using Open Social
/**
* Parses the response to the friend information request and generates
* html to list the friends by 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 += ':<br><ul>';
var viewerFriends = dataResponse.get('viewerFriends').getData();
viewerFriends.each(function(person) {
html += '<li>' + person.getDisplayName();
});
html += '</ul>';
document.getElementById('message').innerHTML = html;
};
18. OpenSocial Service Provider
Interface
* Adding and removing friends
* Adding and removing apps
* Storing activities
* Retrieving activity streams for self and friends
* Storing and retrieving per-app and per-app-per-user data