Being a fan of prototype.js and scriptaculous my self, i was soon taken aback by the arcane javascript API's the Open Social environment offers. Its very much like programming in the old document.getElementById() days, and that can quickly get in the way of quickly writing good and maintainable software.
Hence my second step in the Open Social world was to make a generic Open Social class which could wrap the social functionality (owner, viewer and friends of-) and all its arcane magic into a prototype.js style programming environment, and allow easy loading of all the required social data and wrap it in an uniform data structure.
The result was this class:
osPeople - open social information wrapper
This class can be used in 2 ways, either Extend this class to impliment functionality,
and define the any following functions to hook up to the specific events your interested in:
onInitialize(); called when the class initializes
onLoading(); called when the request.send call has been made and the data is being loaded
onComplete(); called when the person data has been loaded and parse
onError(msg); called when an error occured in the opensocial communication
or call the class with onInitialize, onError, onLoading and/or onComplete functions in the options, for example:
-
new osClass({ viewer:true, owner:true, onLoading: my_loading_function, onComplete: my_complete_function, onError: my_error_func});
to access the social people data you can use the following json arrays:
-
.owner
-
.viewer
-
.ownerFriends
-
.viewerFriends
owner and viewer are single items, where *Friends are array's
each person entry is defined as:
-
person.id (string, unique consistent person id)
-
person.name (display name on the social site)
-
person.isOwner (bool, is this the owner of the page?)
-
person.isViewer (bool, is this the viewer of the page?)
-
person.profile (string, url to the profile page of this person)
-
person.thumb (string, url to the thumbnail image)
Usage: to retrieve only the viewer:
-
new osClass({viewer:true});
To retrieve everything (viewer, owner, & friends):
-
new osClass({viewer:true,owner:true,viewerFriends:true,ownerFriends:true});
other functions:
-
hasError(); returns true when an error has occured
-
getError();
Example of using this as an application class:
-
var myOSClass = Class.create();
-
Object.extend(Object.extend(myOSClass.prototype, osClass.prototype), {
-
onInitialize: function() {
-
// show unloading msg here?
-
},
-
-
onLoaded: function() {
-
// do things with: this.owner, this.viewer, this.ownerFriends and/or this.viewerFriends
-
}
-
}
To make this application load automaticly on load we have to create an open social container (xml file) which people can add to their profile page, and in it create the class in the container load event, like this:

November 11th, 2007 at 9:08 am
[...] Original post by chabotc.com [...]
November 12th, 2007 at 8:18 pm
[...] second article includes the first library you can tell to load (owner, viewer, ownerFriends and/or viewerFriends) information, and presents this information in an [...]
November 15th, 2007 at 4:37 am
Thanks for creating this wrapper. I find the OS api to be a bit arcane as well
November 17th, 2007 at 12:30 pm
Have been reading up on this, looks interesting
February 20th, 2008 at 4:12 am
Hi
I am a container developer and was just wondering why the OpenSocial API is too arcane… this class would make app developers’ life a bit easier.
May 18th, 2008 at 6:35 pm
How do I become a container for Open Social? I read the API Specification on “http://code.google.com/apis/opensocial/docs/0.7/spec.html” but I didn’t find out how do integrate Open Social into my social network. Can you tell me how do do this?
There are lots of .js files mentioned in the specification. Do I have do put these files into the root directory of my website? Then I could paste the data by using PHP and MySQL so that the output is in the javascript file, couldn’t I?
May 18th, 2008 at 6:40 pm
Hi timo,
Your in luck, there is an open source project called ‘Shindig’ that provides you with the functionality you need to become an open social container, see:
http://www.chabotc.com/shindig/
where i write a little about what it is.
If you want an example on how to use this, for this i made the Partuza project which you can find here:
http://www.chabotc.com/partuza/
Shindig is the open social reference container, that implements the open social spec and provides you with the platform to be a container; Partuza is an example social network site that demonstrates how to use this in your own site.
Hope that helps!
June 17th, 2008 at 7:58 am
Hi All,
I get this error very frequently
syntax error
() in frequently calling a servlets and html files also
In the response of the makeRequest is this way
“body”:”",”rc”:”504″
When clicked on the error displayed in firebug,it redirects to a js
file
line 186 >>
}}return{stringify:stringify,parse:function(text){if(/^[\],:{}\s]*
$/.test
(text.replace(/\\["\\\/b-u]/g,”@”).replace(/”[^"\\\n\r]*”|true|false|
null|-
?\d (?:\.\d*)?(?:[eE][ \-]?\d )?/g,”]”).replace(/(?:^|:|,)(?:\s*\[)
/g,”"))){return eval(”(” text “)”)
What eactly does this mean?
I don’t know what might go wrong. I have the same application in
Orkut,FaceBook and don’t have these problems. We need some help,
please…..its Emergency………..