简体   繁体   English

FQL和Graph API:在所有Facebook朋友之间查找共同的朋友

[英]FQL and Graph API: Find Mutual Friends Between All Facebook Friends

I am trying to get the count of mutual friends between a user and each of his or her friends. 我正在尝试获取用户与其每个朋友之间的共同朋友数。

I have looked extensively at the graph api and fql to try and solve this. 我已经广泛地查看了图api和fql来尝试解决此问题。 I have looked at the graph api me/mutualfriends/<uid> 我看过图api me/mutualfriends/<uid>

However, if doing this over a large number of friends (>1k) then it is too much to make a request for the mutual friends between each individual friend. 但是,如果对大量朋友(> 1k)执行此操作,则要求每个单独朋友之间的共同朋友太多了。

I then tried this with batch requests (max 50 at a time) using both FQL and the Graph API. 然后,我使用FQL和Graph API对批处理请求(一次最多50个)进行了尝试。 This still results in one query to get all of the friends, and then N queries for the mutual friends with each individual friend. 这仍然导致一个查询获得所有朋友,然后N个查询与每个单独朋友的共同朋友。 Even batched 50 at a time, this takes quite a long time. 即使一次批处理50个,也要花费很长时间。

This is the main FQL query: 这是主要的FQL查询:

select uid1 from friend where uid2 = FRIEND_ID and uid1 in (select uid2 from friend where uid1 = me())';

This is the graph api url: 这是图形api网址:

/me/mutualfriends/FRIEND_ID

I am using batch processing like: 我正在使用类似的批处理:

$facebook->api('/?batch='.json_encode($batch), 'POST');

Where each query in the batch is an array like: 批处理中的每个查询都是一个数组,如:

$cur = array('method'=>'GET', 'relative_url'=> $relative_url);

Using the graph api instead of fql seems to be faster, but is there a way to get the mutual friends for all the friends in one query? 使用图谱api代替fql似乎更快,但是有没有一种方法可以在一个查询中为所有朋友获得共同朋友? Or is there actually a faster way to do this? 还是实际上有一种更快的方法? I have read about mutual_friend_count at different parts of SO, but have not gotten this to work yet. 我已经在SO的不同部分阅读了有关common_friend_count的信息,但尚未使它起作用。

I jut got mutual_friend_count to work as shown here. 我伸出了Mutual_friend_count的代码,如下所示。 However, I am still curious if you can construct a single FQL query to get this data. 但是,我仍然很好奇您是否可以构造一个FQL查询来获取此数据。

$fql = "SELECT name,mutual_friend_count FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1=me())";

$response = $facebook->api(array(
    'method' => 'fql.query',
    'query' =>$fql,
));     

From Friend with the highest number of mutual friends 来自拥有最多共同朋友的朋友

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

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