here is the complete example. hope you guys find it useful.
Canvas surface:
<div id="content"></div>
<script>
function sendRequest()
{
// Get the container and create a new DataRequest object
var mos = opensocial.Container.get();
var dr = mos.newDataRequest();
dr.add(mos.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), 'viewer');
response = dr.send(requestCallback);
}
function requestCallback(response)
{
if ( response.hadError() == false)
{
var viewerId = response.get('viewer').getData().getId();
viewerName = response.get('viewer').getData().getDisplayName();
var postdata = {
user : viewerId,
};
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
var url = "http://host/myspace_app/canvasconstruction.php";
gadgets.io.makeRequest(url, function (response, url, errored){
if (typeof response.text != 'undefined' || response.text != '')
{
var html = response.text;
document.getElementById('content').innerHTML = "";
document.getElementById('content').style.display = "block";
document.getElementById('content').innerHTML = html;
gadgets.window.adjustHeight();
}
}, params);
}
}
</script>
//-----------------------------------------------------------------------
canvasconstruction.php
require_once('Space.php');
$key = 'http://www.myspace.com/xxxxx';
$secret = 'xxxxxxxxxxx';
$s = new Space($key,$secret);
$hProfile = $s->profile($_REQUEST['user']);
//getting 500 frnds
$user_frnd_info = array();
for ($currentPosition = 1; $currentPosition <= 25; $currentPosition++ )
{
$page = $currentPosition;
$page_size = null;
$list = null;
$temp = $s->friends($user,$page,$page_size,$list);
if ( empty($temp['friends']))
break;
else
{
for ($j=0; $j< count( $temp['friends']) ; $j++)
{
if ( $temp['friends'][$j]['usertype'] !== 'Application' )
$user_frnd_info['friends'][ = $temp['friends'][$j];
}
}
}
print_r($user_frnd_info);
//getting 500 app frnds
$user_frnd_info = array();
for ($currentPosition = 1; $currentPosition <= 25; $currentPosition++ )
{
$page = $currentPosition;
$page_size = null;
$list = 'app';
$temp = $s->friends($user,$page,$page_size,$list);
if ( empty($temp['friends']))
break;
else
{
for ($j=0; $j< count( $temp['friends']) ; $j++)
{
if ( $temp['friends'][$j]['usertype'] !== 'Application' )
$user_frnd_info['friends'][ = $temp['friends'][$j];
}
}
}
print_r($user_frnd_info);