共同朋友数量最多的朋友 [英] Friend with the highest number of mutual friends

查看:83
本文介绍了共同朋友数量最多的朋友的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到与我分享最多的共同朋友.
我尝试通过以下方式使用FQL和graph API进行此操作:

I want to find my friend whom I share with them the highest number of mutual friends.
I tried to do it with FQL and graph API the following way:

  1. 获取当前登录用户的朋友列表.
    FQL:SELECT uid1 FROM friend WHERE uid2="MY_USER_ID" and uid1 IN (SELECT uid1 FROM friend WHERE uid2=me())
    图形API:$facebook->api('/me/friends?format=json&limit=5000')

  1. Get the friends list of the current logged in user.
    FQL: SELECT uid1 FROM friend WHERE uid2="MY_USER_ID" and uid1 IN (SELECT uid1 FROM friend WHERE uid2=me())
    Graph API: $facebook->api('/me/friends?format=json&limit=5000')

对于列表中的每个uid,我可以获取共同朋友的列表并进行计数.
FQL:SELECT uid1 FROM friend WHERE uid2="OTHER_USER" and uid1 IN (SELECT uid1 FROM friend WHERE uid2=me())
图形API:$facebook->api('me/mutualfriends/OTHER_USER')

For each one of the uid's in the list, I can get the list of mutual friends and count it.
FQL: SELECT uid1 FROM friend WHERE uid2="OTHER_USER" and uid1 IN (SELECT uid1 FROM friend WHERE uid2=me())
Graph API: $facebook->api('me/mutualfriends/OTHER_USER')

但是,它需要 TONS 的时间才能通过我的所有朋友运行...
您是否熟悉更好的方法?

HOWEVER, it takes TONS of time to run this through all my friends...
Are you familiar with a better way to do that?

推荐答案

我不确定最终要达到的目标是什么.但是,如果您正在列表中寻找头号朋友,则可以通过获取供稿来实现,然后可以根据帖子数对朋友进行排名.

I am not sure what exactly you want to acheive finally. But if you are looking for top friends in the list you can achieve that by fetching feed and then can rank friends according to number of posts.

$fql="SELECT actor_id FROM stream WHERE filter_key = 'others' AND source_id = me() ORDER BY actor_id LIMIT 3000";
$param=array(
            'method'    => 'fql.query',
            'query'     => $fql,
            'callback'  => ''
        );
        $fqlResult1   =   $this->facebook->api($param);
        $top_frds=array();
        foreach($fqlResult1 as $result1)
        {
            $top_frds[]=$result1['actor_id'];
        }


$new_array = array();
foreach ($top_frds as $key => $value) {
if(isset($new_array[$value]))
    $new_array[$value] += 1;
else
    $new_array[$value] = 1;
}
$top_frds=array();
foreach($new_array as $tuid => $trate)
{
$top_frds[]=array('uid'=>$tuid,'rate'=>$trate);
}

这篇关于共同朋友数量最多的朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆