gpt4 book ai didi

python - 使用 python 和 tweepy 的 twitter "friends"的完整列表

转载 作者:太空狗 更新时间:2023-10-29 21:34:22 24 4
gpt4 key购买 nike

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

是否可以将 tweepy 与 python 2.7.6 一起使用来显示所有 friend 的完整列表?

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

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 个 friend ,ct 变量等于 20。此方法排除了我在 Twitter 上关注的其他用户。

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

最佳答案

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

The number of users to return per page, up to a maximum of 200. Defaults to 20.

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

或者,更好的方法是使用 Cursor,它是 paginated way得到所有的 friend :

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

另见:

关于python - 使用 python 和 tweepy 的 twitter "friends"的完整列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25944037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com