简体   繁体   English

在Python / Django中将用户的facebook / twitter朋友与站点用户进行比较

[英]Comparing user's facebook/twitter friends to site's users in Python/Django

I'm wondering if someone could help guide the approach to this fairly common problem: 我想知道是否有人可以帮助指导解决这个相当普遍的问题的方法:

I'm building a simple site which a user connects their twitter account to sign up. 我正在构建一个简单的网站,用户可以在该网站上连接其Twitter帐户进行注册。 I'd like to create an interface which shows them which of their twitter friends are already using the site. 我想创建一个界面,向他们显示他们的哪些Twitter朋友已经在使用该网站。

So I can get a list the user's twitter friends, and a list of the site's users (which all have the twitter screen name as username, but I'm wondering the most efficient method to compare these lists and create a variable with the commonalities. 因此,我可以获得用户的Twitter朋友的列表以及站点用户的列表(所有用户均具有Twitter屏幕名称作为用户名,但是我想知道最有效的方法来比较这些列表并创建具有通用性的变量。

As an aside, given the Twitter API returns IDs, should I save the twitter user's ID (in addition to their username) when they create an account? 顺便说一句,鉴于Twitter API返回ID,我应该在创建帐户时保存Twitter用户的ID(除了其用户名之外)吗?

Thanks in advance! 提前致谢!

从中创建 ,并使用相交方法:

intersection_set = set(list_a).intersection(list_b)

You should store the twitter user's ID because the username can change at any time, but the id will always be the same. 您应该存储twitter用户的ID,因为用户名可以随时更改,但是ID始终相同。 You should be comparing the id's, not the usernames in the intersection_set that Ofri recommends. 您应该比较ID的名称,而不是Ofri建议的intersection_set中的用户名。

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

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