简体   繁体   English

找共同的朋友

[英]find mutual friends

I'm working on an app using data from the facebook graph api. 我正在使用来自facebook graph api的数据开发一个应用程序。 A user logs in and can generate stuff from his data on fb. 用户登录并可以根据其在fb上的数据生成内容。 We use, among other data, the number of mutual friends between the current user and each of his friends, using the me/mutualfriends/friend_id endpoint. 除其他数据外,我们使用me/mutualfriends/friend_id端点使用当前用户与其每个朋友之间的共同朋友数。 The thing is, that's one request per friend. 事实是,每个朋友一个请求。 Even if we batch the requests, it is usually at least 4 not-so-quick requests. 即使我们对请求进行批处理,通常也至少是4个不太快的请求。

So I'm wondering : we already have all the friends, and we only need the number of mutual friends, not any data about them (and anyway we already have it) : is there a better way, using less requests ? 所以我想知道:我们已经有了所有的朋友,而我们只需要数量的共同朋友,而不需要有关他们的任何数据(无论如何我们已经拥有了):是否有更好的方法,使用更少的请求?

Thanks for your time folks. 谢谢您的宝贵时间。

If you have every user's friends, then you can just take the intersection of two user's array of friends to get mutual friends. 如果您有每个用户的朋友,那么您就可以采用两个用户的朋友数组的交集来获得共同的朋友。

user1_friends = ['a', 'b', 'c']
user2_friends = ['c', 'd', 'e']
mutual = user1_friends & user2_friends

mutual should be equal to ['c'] 共同应等于['c']

This should be far more efficient than reaching out to an endpoint. 这应该比伸向端点要有效得多。

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

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