Getting whole user timeline of a Twitter user

后端 未结 1 1726
一个人的身影
一个人的身影 2020-12-09 18:32

I want to get the all of a user tweets from one Twitter user and so far this is what I came up with:

import twitter
import json
import sys
import tweepy 
fro         


        
相关标签:
1条回答
  • 2020-12-09 19:05

    There's a few issues with your code, including some superfluous imports. Particularly, you don't need to import twitter and import tweepy - tweepy can handle everything you need. The particular issue you are running into is one of pagination, which can be handled in tweepy using a Cursor object like so:

    import tweepy
    
    # Consumer keys and access tokens, used for OAuth
    consumer_key = ''
    consumer_secret = ''
    access_token = ''
    access_token_secret = ''
    
    # OAuth process, using the keys and tokens
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    
    # Creation of the actual interface, using authentication
    api = tweepy.API(auth)
    
    for status in tweepy.Cursor(api.user_timeline, screen_name='@realDonaldTrump', tweet_mode="extended").items():
        print(status.full_text)
    
    0 讨论(0)
提交回复
热议问题