我试图计算朋友朋友的平均数量
例如,如果用户有4个朋友:
结果将
使用PHP和FQL以及图谱API
问题是我认为我发送的fql批处理请求是2大而我没有得到回应
如果有1人知道更好/可行的方法,请帮助
我的代码段:
//get average of friends friends
$friends=$facebook->api('/me?fields=friends');
$friends=$friends['friends'];
if (isset($friends)){
//now we have array of friends
$friends = $friends['data'];
//prepare the query
$queries = array();
foreach ($friends as $friend){
$friendId = $friend['id'];
$query1="SELECT friend_count FROM user WHERE uid = $friendId";
$newArray = array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query1));
$queries[]=$newArray;
}
//send batch request
$batchResponse = $facebook->api('/?batch='.json_encode($queries), 'POST');
//go over all responses get the amount of friends
var_dump ($batchResponse); //this is null ... think the request fails beacuse of its size
答案 0 :(得分:3)
不需要为每个用户的朋友发出批量请求,而是可以使用以下嵌套查询来执行相同的操作,
SELECT friend_count FROM user WHERE uid in (SELECT uid2 from friend where uid1=me())