Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 895
apt45 Avatar asked Feb 24 '18 18:02

apt45


People also ask

What is Tweet mode extended?

When using extended mode, the text attribute of Status objects returned by tweepy. API methods is replaced by a full_text attribute, which contains the entire untruncated text of the Tweet. The truncated attribute of the Status object will be False , and the entities attribute will contain all entities.

How many tweets can be extracted using Tweepy?

Tweepy provides the convenient Cursor interface to iterate through different types of objects. Twitter allows a maximum of 3200 tweets for extraction. These all are the prerequisite that have to be used before getting tweets of a user.

How can I get more than 200 tweets on Tweepy?

To get more then 200, you need to use the cursor on user_timeline and then iterate over the pages. Show activity on this post. From the definition of the count parameter: Specifies the number of Tweets to try and retrieve, up to a maximum of 200 per distinct request.

How do you get a full text tweet?

If we want to get the complete text, pass another parameter tweet_mode = "extended" . From this object, fetch the text attribute present in it. If we want to get the complete text, fetch the attribute full_text.


1 Answers

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
like image 89
John Maged Avatar answered Nov 14 '22 20:11

John Maged