Search code examples
pythonpython-3.xtwittertweepy

How to get old tweets by tweet-ID using python?


I was using Tweepy, but as I discovered in the link (Older tweets Tweepy using Python) I cannot get older tweets using tweppy.

I found some libraries to get older tweets, but I cannot get them by their IDs.

Someone knows how can I get it?


Solution

  • I believe you can use tweepy to find tweets no matter how old they are using get_status()

    example

    # import tweepy
    import tweepy
    
    # api keys from twitter developers
    consumer_key='<your consumer_key here>'
    consumer_secret='<your consumer_secret here>'
    access_token='<your access_token here>'
    acess_token_sectret='<your acess_token_sectret here>'
    
    # login to twitter 
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, acess_token_sectret)
    auth.secure = True
    api = tweepy.API(auth)
    
    
    
    # define the id of the tweet you are looking for
    id = 1181329749966295041
    
    # get the tweet
    tweet = api.get_status(id)
    # print the text of the tweet
    print(tweet.text)