【问题标题】:Full list of twitter "friends" using python and tweepy使用 python 和 tweepy 的 twitter“朋友”的完整列表
【发布时间】:2014-11-14 15:29:57
【问题描述】:

我所说的朋友是指我关注的所有 Twitter 用户。

是否可以在 python 2.7.6 中使用 tweepy 来显示所有朋友的完整列表?

我发现可以使用以下代码显示包含我的一些朋友的列表。当然是在处理授权之后。

api = tweepy.API(auth)
user = api.get_user('MyTwitterHandle')
print "My Twitter Handle:" , user.screen_name
ct = 0

for friend in user.friends():
    print friend.screen_name
    ct = ct + 1


print "\n\nFinal Count:", ct

此代码成功打印了我在 Twitter 上最近的 20 个朋友,ct 变量等于 20。此方法排除了我在 Twitter 上关注的其他用户。

是否可以在 Twitter 上显示我关注的所有用户?或者至少有一种方法可以调整参数以允许我加入更多朋友?

【问题讨论】:

    标签: python python-2.7 twitter tweepy


    【解决方案1】:

    根据source codefriends() 指的是GET friends / list twitter 端点,它允许传入count 参数:

    每页返回的用户数,最大为 200。默认为 20。

    这将允许您通过friends() 获得 200 个朋友。

    或者,更好的方法是使用Cursor(即paginated way)来获取所有朋友:

    for friend in tweepy.Cursor(api.friends).items():
        # Process the friend here
        process_friend(friend)
    

    另见:

    【讨论】:

    • 游标方法似乎适用于这个应用程序,它是否也限制为200但默认情况下?
    • @John 不,不限于 200。
    • @alecxe 我们可以发出多少寻呼请求?如果任何用户有 5000 个关注者,那么如果分页限制设置为 100,则 Twitter 给出“已达到 Twitter 限制”。
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 2012-02-12
    • 2012-10-20
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    相关资源
    最近更新 更多