【问题标题】:Get/list all tweets of all users my account follow获取/列出我的帐户关注的所有用户的所有推文
【发布时间】:2021-04-04 10:55:23
【问题描述】:

我正在使用 python tweepy 连接 twitter 端点,列出任何单个用户的所有推文非常简单。也可以阅读我帐户的“关注”列表,所以从技术上讲,我可以获得所有关注用户的所有推文列表,事情是,这将是很多单独的 API 调用。 有没有办法有效地增加这个量?

【问题讨论】:

    标签: twitter tweepy


    【解决方案1】:

    您无法一次性获取所有内容,Twitter 有速率限制以防止这种情况发生,但此脚本将尽可能多地从每个用户那里获取:

    import tweepy
    
    # Put your API keys here
    CONSUMER_KEY = ""
    CONSUMER_SECRET = ""
    ACCESS_TOKEN = ""
    ACCESS_TOKEN_SECRET = ""
    
    # Authenticate to Tweepy and wait if you get rate limited
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True)
    
    # For each user that you follow.....
    for user in tweepy.Cursor(api.friends, screen_name="pigeonburger").items():
    
        # Get each user's username and print out 100 of their tweets
        username = user._json['screen_name']
        print(api.user_timeline(screen_name = username, count = 100))
        # Do what you want with those tweets after
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-05
      • 2023-04-11
      • 2013-01-28
      • 2015-05-31
      • 1970-01-01
      • 2023-04-06
      • 2017-05-19
      相关资源
      最近更新 更多