OpenSocial: How to Detect Profile Owner
One of the common tasks for OpenSocial application developer is to distinguish between ordinary profile viewer and profile viewer who is "OWNER" which means installed the application. It is needed to perhaps display different content according to the "VIEWER".
The following profile content example snippet demonstrates how to perform this task:
< script type="text/javascript"> var os; var dataReqObj; function init() { os = opensocial.Container.get(); if (os != null) { dataReqObj = os.newDataRequest(); var viewerReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER); dataReqObj.add(viewerReq); dataReqObj.send(viewerResponse); } else { // some code } } function viewerResponse(data) { var viewer = data.get(opensocial.DataRequest.PersonId.VIEWER).getData(); if (viewer != null) { // some code if (viewer.isOwner()) { // do something - OWNER } else { // do something - NOT OWNER } } else { // some code } } init(); < /script>
Enjoy :)
Saturday, August 23, 2008 12:04 AM