9

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??

apt45
  • 412
  • 1
  • 6
  • 14

2 Answers2

11

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
John Maged
  • 185
  • 3
  • 7
0

This worked for me :

if 'retweeted_status' in status._json:
   if 'extended_tweet' in status._json['retweeted_status']:
      text = 'RT @'+status._json['retweeted_status']['user']['screen_name']+':'+status._json['retweeted_status']['extended_tweet']['full_text']
   else:
      text = 'RT @'+status._json['retweeted_status']['user']['screen_name']+':' +status._json['retweeted_status']['text']
else:
   if 'extended_tweet' in status._json:
      text = status._json['extended_tweet']['full_text']
   else:
      text = status.text
Lino
  • 41
  • 1
  • 5