Friends1
";
//Get level 1 friends aka user friends
$friends1=getTwitterFriends($username);
//Get level 2 friends aka friends of friends
print_r($friends1);
echo "
Friends2
";
$friends2=array();
foreach($friends1 as $f){
$friends2[$f]=getTwitterFriends($f);
}
print_r($friends2);
//Get level 3 friends aka go get a coffee
$friends3=array();
foreach($friends2 as $a){
for($i=0; $i
Friends3
";
print_r($friends3);
//Create XML file for graph FORMATO:
//
//
$VBOF='mikinum7Your Twitter friends graph';
$VEOF='';
$xmlNodesBOF="";
$xmlNodesEOF="";
$xmlEdgesBOF="";
$xmlEdgesEOF="";
$xmlFriends1="";
foreach($friends1 as $f){
$xmlFriends1.="";
}
$xmlFriends2="";
foreach($friends2 as $a){
$xmlFriends2.=createXMLNodes($a);
}
$xmlFriends3="";
foreach($friends3 as $a){
$xmlFriends3.=createXMLNodes($a);
}
$xmlNodes=$xmlFriends1.$xmlFriends2.$xmlFriends3;
$xmlEdges="";
$numEdge=0;
//creo archi primo livello
foreach($friends1 as $f){
$xmlEdges.="";
$numEdge++;
}
//creo archi secondo livello
foreach($friends1 as $f){
foreach($friends2[$f] as $f2){
$xmlEdges.="";
$numEdge++;
}
}
//create level 3 edges
foreach($friends1 as $f){
foreach($friends2[$f] as $f2){
foreach($friends3[$f2] as $f3){
$xmlEdges.="";
$numEdge++;
}
}
}
$xml=$VBOF.$xmlNodesBOF.$xmlNodes.$xmlNodesEOF.$xmlEdgesBOF.$xmlEdges.$xmlEdgesEOF.$VEOF;
$write_file = fopen("grafo.gexf","w");
fwrite($write_file,$xml);
fclose($write_file);
function getTwitterFriends($user){
$jsonurl = 'http://api.twitter.com/1/statuses/friends/'.$user.'.json';
$json = @file_get_contents($jsonurl,0,null,null);
if($json === false){
echo 'badrequest for '.$user.'
';
//exit;
return null;
}
$json_output = json_decode($json);
$friends=array();
for($i=0; $i{'screen_name'};
}
return $friends;
}
function createXMLNodes($array){
$nodiArray="";
//foreach($array as $a){
for($i=0; $i";
}
//}
return $nodiArray;
}
?>