<Module>
<ModulePrefs title="hello world example" >
<Require feature="opensocial-0.8" />
</ModulePrefs>
<Content type="html"><![CDATA[
><div id="dom_handle"></div><script language="javascript"> function getUserCharming(userId) { var req = opensocial.newDataRequest(); var params1 = {}; params1[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.THUMBNAIL_URL, opensocial.Person.Field.GENDER]; req.add(req.newFetchPersonRequest(userId, params1), "user");
var idspec = opensocial.newIdSpec({ "userId" : userId, "groupId" : "FRIENDS" }); var params2 = {}; params2[opensocial.DataRequest.PeopleRequestFields.MAX] = 100; params2[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.THUMBNAIL_URL, opensocial.Person.Field.GENDER]; req.add(req.newFetchPeopleRequest(idspec, params2), "friends"); req.send(showCharming); } function getOwnerCharming() { getUserCharming("OWNER"); }
var userGender; var userCharming; var friendCount; var html; function showCharming(response) { var user = response.get("user").getData(); var friends = response.get("friends").getData();
var userPic = user.getField(opensocial.Person.Field.THUMBNAIL_URL); userGender = user.getField(opensocial.Person.Field.GENDER).displayValue; userCharming = 0; friendCount = 0; if (friends) { friends.each(computeCharming); } postCharmingActivity(user); html = "<img src='" + userPic + "'></img>" + user.getDisplayName() + "'s Charming is: " + userCharming + "/" + friendCount + "<hr><br>";
if (friends) { friends.each(showFriendLink); } document.getElementById("dom_handle").innerHTML = html; } function postCharmingActivity(user) { if(user.isViewer()) { var params = {}; params[opensocial.Activity.Field.TITLE] = user.getDisplayName() + "'s Charming is: " + userCharming + "/" + friendCount; var activity = opensocial.newActivity(params); opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH); } } function computeCharming(friend) { friendCount++; var friendGender = friend.getField(opensocial.Person.Field.GENDER).displayValue; if(friendGender != userGender){ userCharming++; } } function showFriendLink(friend) { var friendGender = friend.getField(opensocial.Person.Field.GENDER).displayValue; var friendPic = friend.getField(opensocial.Person.Field.THUMBNAIL_URL); html += "<a href='javascript:getUserCharming(\"" + friend.getId() + "\")'><img src='" + friendPic + "' title='" + friend.getDisplayName() + "' style='margin:20px;'></img></a>"; } gadgets.util.registerOnLoadHandler(getOwnerCharming);</script>
]]></Content>
</Module>
view-source:http://hosting.gmodules.com/ig/gadgets/file/106174878109025583958/myosapp.xml
<ModulePrefs title="hello world example" >
<Require feature="opensocial-0.8" />
</ModulePrefs>
<Content type="html"><![CDATA[
><div id="dom_handle"></div><script language="javascript"> function getUserCharming(userId) { var req = opensocial.newDataRequest(); var params1 = {}; params1[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.THUMBNAIL_URL, opensocial.Person.Field.GENDER]; req.add(req.newFetchPersonRequest(userId, params1), "user");
var idspec = opensocial.newIdSpec({ "userId" : userId, "groupId" : "FRIENDS" }); var params2 = {}; params2[opensocial.DataRequest.PeopleRequestFields.MAX] = 100; params2[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.THUMBNAIL_URL, opensocial.Person.Field.GENDER]; req.add(req.newFetchPeopleRequest(idspec, params2), "friends"); req.send(showCharming); } function getOwnerCharming() { getUserCharming("OWNER"); }
var userGender; var userCharming; var friendCount; var html; function showCharming(response) { var user = response.get("user").getData(); var friends = response.get("friends").getData();
var userPic = user.getField(opensocial.Person.Field.THUMBNAIL_URL); userGender = user.getField(opensocial.Person.Field.GENDER).displayValue; userCharming = 0; friendCount = 0; if (friends) { friends.each(computeCharming); } postCharmingActivity(user); html = "<img src='" + userPic + "'></img>" + user.getDisplayName() + "'s Charming is: " + userCharming + "/" + friendCount + "<hr><br>";
if (friends) { friends.each(showFriendLink); } document.getElementById("dom_handle").innerHTML = html; } function postCharmingActivity(user) { if(user.isViewer()) { var params = {}; params[opensocial.Activity.Field.TITLE] = user.getDisplayName() + "'s Charming is: " + userCharming + "/" + friendCount; var activity = opensocial.newActivity(params); opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH); } } function computeCharming(friend) { friendCount++; var friendGender = friend.getField(opensocial.Person.Field.GENDER).displayValue; if(friendGender != userGender){ userCharming++; } } function showFriendLink(friend) { var friendGender = friend.getField(opensocial.Person.Field.GENDER).displayValue; var friendPic = friend.getField(opensocial.Person.Field.THUMBNAIL_URL); html += "<a href='javascript:getUserCharming(\"" + friend.getId() + "\")'><img src='" + friendPic + "' title='" + friend.getDisplayName() + "' style='margin:20px;'></img></a>"; } gadgets.util.registerOnLoadHandler(getOwnerCharming);</script>
]]></Content>
</Module>
view-source:http://hosting.gmodules.com/ig/gadgets/file/106174878109025583958/myosapp.xml