opensocial

<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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值