Extract full tweet Tweepy Python

Question:

I can’t find a way to get the full text of a tweet, I have everything activated, tweet_mode="extended" and I print tweet.full_text, but it keeps getting the trimmed tweet, I’ve looked directly at tweet._json and it’s also trimmed there I don’t understand why

import tweepy
import configparser
from datetime import datetime

def apiTwitter(): #Para conectarse a twitter y scrapear con su api, devuelve objeto de tweepy cheto para scrapear twitter
    # read credentials
    config = configparser.ConfigParser()
    config.read('credentialsTwitter.ini')

    api_key = config['twitter']['api_key']
    api_key_secret = config['twitter']['api_key_secret']

    access_token = config['twitter']['access_token']
    access_token_secret = config['twitter']['access_token_secret']

    # authentication
    auth = tweepy.OAuthHandler(api_key,api_key_secret)
    auth.set_access_token(access_token,access_token_secret)

    api=tweepy.API(auth)

    return api


api=apiTwitter() #Con api ahora podemos scrapear todo twitter de forma sencilla
tweets = api.user_timeline(screen_name='kowaalski_',tweet_mode="extended", count=1)
tweet=tweets[0]
#print(tweet._json)
print(f'Tweet text: {tweet.full_text}')

Asked By: Chupitastiiks

||

Answers:

This is because the first tweet is a retweet and the full_text attribute of a retweet can still be truncated. You have to access the full_text attribute of the retweeted status instead.

Basic example:

try:
    print(tweet.retweeted_status.full_text)
except AttributeError:  # So this is not a Retweet
    print(tweet.full_text)
Answered By: Mickaël Martinez
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.