将 Geoff 的答案带到下一步,这里是 PHP 中的完整解决方案。
首先,这是 Geoff 的 FQL:
SELECT uid1, uid2 FROM friend
WHERE uid1 IN
(SELECT uid2 FROM friend WHERE uid1=me())
AND uid2 IN
(SELECT uid2 FROM friend WHERE uid1=me())
这是用于检索 JSON 并检查哪个朋友与您有最多共同朋友的 PHP 代码。(确保替换 URL 中的访问令牌。)
<?php
$jsonurl = "https://api.facebook.com/method/fql.query?query=SELECT+uid1%2C+uid2+FROM+friend++%0A++WHERE+uid1+IN+%0A++%28SELECT+uid2+FROM+friend+WHERE+uid1%3Dme%28%29%29%0A+++AND+uid2+IN+%0A++%28SELECT+uid2+FROM+friend+WHERE+uid1%3Dme%28%29%29&access_token=***INSERTACCESSTOKENHERE***&format=json";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json,true);
for ($friendship = 0; $friendship <= count($json_output); $friendship++)
{
$firstfriend = $json_output[$friendship]["uid1"];
$mutualfriendscount[$firstfriend] = isset($mutualfriendscount[$firstfriend]) ? $mutualfriendscount[$firstfriend] + 1 : 1;
}
$mostmutualfriends_count = 0;
foreach ($mutualfriendscount as $friend => $mutualfriendcount)
{
if ($mutualfriendcount > $mostmutualfriends_count)
{
$mostmutualfriends_count = $mutualfriendcount;
$mostmutualfriends_id = $friend;
}
}
echo "ID $mostmutualfriends_id has the most number of mutual friends with you: $mostmutualfriends_count."
?>