【问题标题】:Tweepy Cursor vs Iterative for low API calls用于低 API 调用的 Tweepy 游标与迭代
【发布时间】:2012-11-04 05:48:32
【问题描述】:

我正在编写一个简单的Tweepy 应用程序来娱乐,但我真的受限于我有多少 API 调用(介于 150 到 350 之间)。因此,为了解决这个问题,我正在寻找减少通话的方法。 Tweepy 有一个内置的光标系统。例如:

# Iterate through all of the authenticated user's friends
for follower in tweepy.Cursor(api.followers).items():
    follower.follow()

对于那些熟悉这个库的人。上面的例子会比简单的效率更高还是更低......

for follower in api.followers_ids():
    api.follow(follower)

除了使用 Cursor 方法比迭代方法简单之外,还有其他优点吗?

提前致谢。

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    如果我没记错我对tweepy 的使用,Cursor 对象会自动对n 的许多元素进行分页...例如,如果有 10,000 个结果,而 Twitter 一次返回(比如说)200 个,然后使用 Cursor 将返回全部 10,000,但必须拨打电话才能继续检索下一个。

    OTOH,api.followers_ids() 只返回结果的第一“页”,所以可能是前 100 个或其他。

    【讨论】:

    • api.followers_ids() 只会返回前 5000 个用户,因此可以安全地假设它不是一个因素。在这种情况下哪个最好?
    猜你喜欢
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2013-11-23
    相关资源
    最近更新 更多