Created
June 26, 2012 01:41
-
-
Save kastork/2992626 to your computer and use it in GitHub Desktop.
OpenSocial gadget example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Module> | |
<ModulePrefs title="Gifts part 1 - Friends"> | |
<Require feature="opensocial-0.8"/> | |
<Require feature="dynamic-height" /> | |
</ModulePrefs> | |
<Content type="html"> | |
<![CDATA[ | |
<script type="text/javascript"> | |
function loadFriends() { | |
var req = opensocial.newDataRequest(); | |
req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER), 'viewer'); | |
var viewerFriends = opensocial.newIdSpec({ "userId" : "VIEWER", "groupId" : "FRIENDS" }); | |
var opt_params = {}; | |
opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 100; | |
req.add(req.newFetchPeopleRequest(viewerFriends, opt_params), 'viewerFriends'); | |
req.send(onLoadFriends); | |
} | |
function onLoadFriends(data) { | |
console.log(data); | |
var viewer = data.get('viewer').getData(); | |
var viewerFriends = data.get('viewerFriends').getData(); | |
html = new Array(); | |
html.push('<ul>'); | |
viewerFriends.each(function(person) { | |
if (person.getId()) { | |
html.push('<li>', person.getDisplayName(), '</li>'); | |
} | |
}); | |
html.push('</ul>'); | |
document.getElementById('friends').innerHTML = html.join(''); | |
gadgets.window.adjustHeight(); | |
} | |
function init() { | |
loadFriends(); | |
} | |
gadgets.util.registerOnLoadHandler(init); | |
</script> | |
<div id='main'> | |
Your friends: | |
<div id='friends'></div> | |
</div> | |
]]> | |
</Content> | |
</Module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment