Check if the Viewer is logged in and has the right permissions
The Viewer information is not always available. You need to check if this is needed.
<?xml version="1.0" encoding="UTF-8" ?> <Module> <ModulePrefs title="Check Viewer permission" summary="" description="" author="" author_email="" thumbnail="" screenshot="" height="380"> <Require feature="opensocial-0.7"/> </ModulePrefs> <Content type="html"> <![CDATA[ <div id='content'></div> <br> <script type="text/javascript"> var getViewer = function(responseItem) { if(responseItem.hadError()) { var sErrorcode = responseItem.getErrorCode(); if(sErrorcode == 'forbidden') { document.getElementById('content').innerHTML = "You are not logged in, please log in first."; } else if(sErrorcode == 'unauthorized') { document.getElementById('content').innerHTML = "This application can't see your information because you will have to give permission to share your information. Please click the button below."; } } if(opensocial.hasPermission(opensocial.Permission.VIEWER)) { document.getElementById('content').innerHTML = "You are logged in and your public information is available."; } } var isViewer = function() { opensocial.requestPermission([opensocial.Permission.VIEWER], 'This reason sentence is not used at the moment', getViewer); } </script> <input type="button" value="Check if Viewer information is available" onClick="isViewer();"> ]]> </Content> </Module>
Example install (Make sure you're not in OpenSocial Sandbox mode)