简体   繁体   中英

Get/list all tweets of all users my account follow

I am using python tweepy to connect the twitter end point, and it's very simple to list all of any single user's tweets. It is also possible to read my account's "following" list, so technicly I can get the list of all the tweets by all of my followed users, thing is, it will be lot's and lot's of seperate API calls. Is there a way to bulk this effectively?

You're not going to be able to get them all in one go, Twitter has rate limits to prevent that, but this script will get as many from each user as possible:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM