以下是Geoff的答案,下面是PHP中的一個完整解決方案。
首先,這裏是傑夫的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())
這裏是PHP代碼檢索JSON和檢查哪個朋友有最共同的朋友和你在一起。 (請確保您更換您的訪問令牌的網址。)
<?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."
?>
Sandy&@talonmies:我返回的數組按用戶標識排序,而不是按'速率'值排序。 另一件事,它並不侷限於我現在的朋友,這意味着沒有和我交往的用戶在列表中。 –
按'費率'排序可能是這樣的: http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/ 但我仍然需要第二個問題的解決方案。 –