Top

Hawkee Most Vocal Friends


OpenSocial Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  6.0 (of 1 scores)
Date Added  Aug 02, 2008
Last Updated  Aug 22, 2008
Tags  comments  friends  opensocial  social 

Introduction

This snippet will display each of your Hawkee friends sorted by the number of comments they've posted. It uses the viewer and person objects to build an array of friends, then sorts by a custom person value, comments.

This snippet is based on the Google devguide code for displaying friends:

http://code.google.com/apis/opensocial/docs/0.7/devguide.html

You may test this in the OpenSocial Sandbox provided by Hawkee. To make your own snippet, direct the sandbox to the URL to your snippet code on your web host.



Grab the Code

<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Most Vocal Friends">
  <Require feature="opensocial-0.7"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
 
<script type="text/javascript">
 
  function getData() {    
    var req = opensocial.newDataRequest();
    req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), 'viewer');
    req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS), 'viewerFriends');
    req.send(onLoadFriends);
  };
 
  function byComments(a, b)
  {
  	a = a.getField('comments');
  	b = b.getField('comments');
	return b-a;
  }
 
  function onLoadFriends(dataResponse)
  {
    var viewer = dataResponse.get('viewer').getData();
	var html = 'Hello ' + viewer.getDisplayName() + " here are your most vocal friends:<br><br>";
 
    var viewerFriends = dataResponse.get('viewerFriends').getData();
 
	friend_array = [];
    viewerFriends.each(function(person)
	{
		friend_array.push(person);
	});
 
	friend_array.sort(byComments);
 
	for(t=0; t < friend_array.length; t++)
	{
		var person = friend_array[t];
		var rank = t + 1;
 
		html += "<div style='float: left; width: 130px; height: 160px; text-align: left;'><div style='float: left; width: 30px;'><b>#"+rank+".</b></div><div style='float: left;'>";
		var thumb = person.getField('thumbnailUrl');
		var profile_url = person.getField('profileUrl')
 
		html += "<a href='" + profile_url + "' target='_top'><b>";
      	html += person.getDisplayName() + '</b><br>';
		if(thumb) { html += '<img src="' + thumb + '" border=0></a><br>'; }
		var comments = person.getField('comments')
		html += "Comments: <b><a href='" + profile_url + "comments/?user_toggle=sent' target='_top'>"+comments+"</a></b></div></div>";
    }
 
    document.getElementById('message').innerHTML = html;
  };
 
  gadgets.util.registerOnLoadHandler(getData);
 
  </script>
  <div id="message"> </div>  
 
]]></Content>
</Module>
 
 
 

Comments

  (1)  RSS
Eugenio
Comments: 1,193
 
OpenSocial Snippet:  Hawkee Most Vocal Friends
Posted on Aug 2, 2008 8:32 pm
fuxin nice hawkeh

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom