$ret_obj = $facebook->api('/me/permissions', 'GET');
//checking app permissions, we need 'read_stream' perms to access the feed
$ret_obj2=$ret_obj['data'];
$ret_obj3=$ret_obj2['0'];
//print_r($ret_obj3);
if (! isset($ret_obj3['read_stream']) || $ret_obj3['read_stream']=='0' ) {
//offer to get perms
$mynum=rand(1000000001,9999999999); //random state for safety
$mystate="slaves".strval($mynum);
$the_query="INSERT INTO states (fbid,code,time) VALUES ('".$user_id."','".$mystate."','".time()."')";
//print $the_query;
mysql_query($the_query) or print(mysql_error());
print("<a target='_top' href='http://www.facebook.com/dialog/oauth/?client_id=".AppInfo::appID()."&redirect_uri=http%3A%2F%2Fapps%2Efacebook%2Ecom%2Fmyapp%2F&state=".$mystate."&scope=read_stream'>Grant permissions</a>");
} else {
//we have read_stream perms
$ret_obj = $facebook->api('/me/home', 'GET');
$ret_obj2=$ret_obj['data'];
print("<br />");
$myarr1= array(); //keeping their ids in an array to remove duplicates
foreach ($ret_obj2 as $value) {
$myval = ($value['from']);
if (array_search($myval['id'],$myarr1)===false) {
$myarr1[]=$myval['id'];
print("<a href='index.php?a=userview&u=".$myval['id']."'><img style='margin:5px;' src='http://graph.facebook.com/".$myval['id']."/picture'></a>");
}
}
}