简体   繁体   English

是否可以使用API​​查找Facebook共同朋友?

[英]Is it possible to find Facebook mutual friends using the API?

I was wanting to find out if it is possible using the Facebook API or Open Graph and two users ID to out put there mutual friends? 我想确定是否可以使用Facebook API或Open Graph和两个用户ID来放置共同的朋友?

As i have managed to do this but it only lists the mutual friends that are 'playing your game' not the whole list. 因为我设法做到了,但它只列出了正在“玩游戏”的共同朋友,而不是整个列表。

bellow is the function i have created: 下面是我创建的函数:

function getMutualFriends($facebook, $uid1, $uid2,$amount=3){
    $random_ids     = array();
    try {
        $param  =   array(
                    'method'  => 'friends.getMutualFriends',
                    'source_uid'    => $uid1,
                    'target_uid'  => $uid2,
                    'callback'=> ''
                );
        $mutualFriends   =   $facebook->api($param);
        if(count($mutualFriends) < $amount){
            $amount = count($mutualFriends);
        }
        $random = pickrandom($mutualFriends,$amount);

        for($i=0; $i<$amount; $i++){
            $random_ids[] = get_name($random[$i]);
        }
        $output = implode(",\n", $random_ids);
        print_r($output);
    //  print_r($mutualFriends);

    }
    catch(Exception $o) {
        print_r($o);
    }
   // return 'None';
}

The method that you are using ( friends.getMutualFriends ) is of the REST API which is deprecated: 您正在使用的方法( friends.getMutualFriends )是不推荐使用的REST API:

Please note: We are in the process of deprecating the REST API. 请注意:我们正在淘汰REST API。 We have added a Graph API equivalent of this call which is the 'mutualfriends' connection of the User object. 我们添加了与此调用等效的Graph API,它是User对象的“互惠”连接。 An example call to this is /PROFILE_ID/mutualfriends/FRIEND_ID which will return the mutual friends that PROFILE_ID has with FRIEND_ID. 一个示例调用是/PROFILE_ID/mutualfriends/FRIEND_ID ,它将返回PROFILE_ID与FRIEND_ID拥有的共同朋友。

All you need to know is right there, just use the mutualfriends connection of the User object . 您所需要知道的就是在那里,只需使用User对象的等连接即可

Also, if you want to compare two users who installed your app then you can just get the friends of both users ( USER_ID/friends ) and compare yourself. 另外,如果您想比较安装了该应用程序的两个用户,则可以只获得两个用户的朋友( USER_ID/friends )并进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM