Search code examples
pythontwittertweepy

tweepy: truncated tweets when using tweet_mode='extended'


This is my code in python

import tweepy
import csv

consumer_key = "?"
consumer_secret = "?"
access_token = "?"
access_token_secret = "?"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

search_tweets = api.search('trump',count=1,tweet_mode='extended')
print(search_tweets[0].full_text)
print(search_tweets[0].id)

and the output is the following tweet

RT @CREWcrew: When Ivanka Trump has business interests across the world, we have to 
ask if she’s representing the United States or her busi…
967462205561212929

which is truncated, although I used tweet_mode='extended'.

How can I extract the full text??


Solution

  • I've had the same problem as you recently, this happened for the retweets only, I found that you can find the full text under here: tweet._json['retweeted_status']['full_text']

    Code snippet:

    ...
    search_tweets = api.search('trump',count=1,tweet_mode='extended')
    for tweet in search_tweets:
        if 'retweeted_status' in tweet._json:
            print(tweet._json['retweeted_status']['full_text'])
        else:
            print(tweet.full_text)
    ...
    

    EDIT Also please note that this won't show RT @.... at the beginning of the text, you might wanna add RT at the start of the text, whatever suits you.

    EDIT 2 You can get the name of the author of the tweet and add it as the beginning as follows

    retweet_text = 'RT @ ' + api.get_user(tweet.retweeted_status.user.id_str).screen_name