【问题标题】:How do I avoid rate limit with tweepy Twitter API?如何避免使用 tweepy Twitter API 的速率限制?
【发布时间】:2019-08-23 22:41:47
【问题描述】:

我第一次使用 tweepy twitter API,需要一些帮助...在下面的代码块中,我循环遍历用户 ID 列表(存储为“帐户”)和每个帐户我正在使用 tweepy.Cursor 来查找他们关注的 ID 列表(他们的“朋友”)。我检查与我关注的帐户的匹配项(存储在“ids”中),然后将匹配项存储为数据框。

我遇到的问题是我不断收到“达到速率限制”错误。请问如何避免这种情况?我假设有一种更聪明的方法可以做到这一点!

谢谢。

df_list = []

for account in accounts:
  friends = []
  for page in tweepy.Cursor(api.friends_ids, id=account).pages():
    friends.extend(page)

  friends = pd.Series(friends)
  matches = friends[friends.isin(ids)]

  d = {'friend_id' : account, 'common_friends' : matches}
  matches = pd.DataFrame(data=d)
  df_list.append(matches)

final_df = pd.concat(df_list)

【问题讨论】:

标签: python api twitter tweepy


【解决方案1】:

你可以使用:

api = tweepy.API(auth, wait_on_rate_limit=True)

当您达到最大请求时,停止并等待,直到可以再次发送请求。

【讨论】:

    猜你喜欢
    • 2014-02-14
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 2022-08-19
    • 2020-11-22
    • 2019-11-23
    相关资源
    最近更新 更多