Php Facebook Graph API获取平均用户数量;“朋友之友”;使用fql
我正在计算平均朋友数量 例如,如果用户有4个朋友:Php Facebook Graph API获取平均用户数量;“朋友之友”;使用fql,php,facebook,facebook-graph-api,facebook-fql,facebook-apps,Php,Facebook,Facebook Graph Api,Facebook Fql,Facebook Apps,我正在计算平均朋友数量 例如,如果用户有4个朋友: 朋友A和5个朋友 朋友B和10个朋友 朋友C和15个朋友 朋友数量未知的朋友D(假设此信息对用户不可见) 结果是 平均好友数=10 计算出的朋友数=3 朋友总数=4 为此使用PHP、FQL和图形API 问题是,我认为我发送的fql批处理请求太大了,并且没有得到响应 如果有人知道更好的方法/工作方法,请帮助 我的代码片段: //get average of friends friends $friends=$f
- 平均好友数=10
- 计算出的朋友数=3
- 朋友总数=4李>
//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
不需要为用户的每个朋友发出批处理请求,而是可以使用以下嵌套查询执行相同的操作
SELECT friend_count FROM user WHERE uid in (SELECT uid2 from friend where uid1=me())