简体   繁体   English

使用Python查找Twitter朋友

[英]Find Twitter friends with Python

I create a list of Twitter profiles and I want to download their friends (the users they follow). 我创建了一个Twitter个人资料列表,我想下载他们的朋友(他们关注的用户)。

I registered on Twitter devs, but I cannot do it through the API without authenticate each user. 我在Twitter开发人员上注册,但是如果不对每个用户进行身份验证,就无法通过API进行注册。

Do you know any other way which may let me download friends list without putting every user on my list to authenticate? 您是否知道其他方法可以让我下载朋友列表而无需将每个用户都放在列表中进行身份验证?

Try using the streaming API, Twitter doesn't really have a friend list its more like followers. 尝试使用流式API,Twitter并没有像其关注者那样真正拥有好友列表。 Followers are not necessary consider as friends. 跟随者不一定要考虑为朋友。 You want to start from your profiles and crawl each of follower and get their followers. 您想从个人资料开始,抓取每个关注者并获取他们的关注者。

def extract_followers(user_id, limit):

    cursor = -1
    ids = []
    while cursor != 0:

        # Assume you have some method to make the twitter connection request where you can pass set of userIds)
        response = twitter_connection(ids, cursor)

        if response is not None:
            ids += response['ids']
            cursor = response['next_cursor']

        print >> sys.stderr, 'Fetched %i total ids for %s' % (len(ids), user_id)

        if len(ids) >= limit or response is None:
            break

    return ids

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

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