Tweepy Cursor vs Iterative for low API calls

依然范特西╮ 提交于 2019-12-13 04:25:29

问题


I am writing a simple Tweepy application for fun, but am really limited to how many API calls I have (anywhere between 150 and 350). So to account for this I am looking for ways to cut calls. Tweepy has a cursor system built in. Eg:

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

For those who are familiar with this library. Would the above example be more or less efficient than simply...

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

Are there any other advantages apart from simplicity to use the Cursor method over an iterative method?

Thanks in advance.


回答1:


If I remember correctly from my use of tweepy, a Cursor object automatically paginates over n many elements... For instance, if there are 10,000 results, and Twitter returns (say) 200 at a time, then using the Cursor will return all 10,000 but will have to make a call to keep retrieving the next ones.

OTOH, api.followers_ids() only returns the first "page" of results, so maybe the first 100 or whatever.



来源:https://stackoverflow.com/questions/13213548/tweepy-cursor-vs-iterative-for-low-api-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!