Getting full tweet text from "user_timeline" with tweepy
Question:
I am using tweepy to fetch tweets from a user’s timeline using the script included here. However, the tweets are coming in truncated:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
new_tweets = api.user_timeline(screen_name = screen_name,count=200, full_text=True)
Returns:
Status(contributors=None,
truncated=True,
text=u"#Hungary's new bill allows the detention of asylum seekers
& push backs to #Serbia. We've seen push backs before sou2026 https://
t.co/iDswEs3qYR",
is_quote_status=False,
...
That is, for some i
, new_tweets[i].text.encode("utf-8")
appears like
#Hungary's new bill allows the detention of asylum seekers &
push backs to #Serbia. We've seen push backs before so…https://t.co/
iDswEs3qYR
Where the ...
in the latter replaces text that would normally be displayed on Twitter.
Does anyone know how I can override truncated=True
to get the full text on my request?
Answers:
Instead of full_text=True you need tweet_mode=”extended”
Then, instead of text you should use full_text to get the full tweet text.
Your code should look like:
new_tweets = api.user_timeline(screen_name = screen_name,count=200, tweet_mode="extended")
Then in order to get the full tweets text:
tweets = [[tweet.full_text] for tweet in new_tweets]
Manolis’s answer is good but not complete. To get the extended version of a tweet (as in Manoli’s version), you would do :
tweetL = api.user_timeline(screen_name='sdrumm', tweet_mode="extended")
tweetL[8].full_text
'Statement of the day at #WholeChildSummit2019 - “‘SOME’ is not a number, and ‘SOON’ is not a time!” IMO, this is why educational systems get stuck. Who in your system will initiate change? TODAY! #HSEFutureReady'
However, if this tweet is a retweet, you’ll want to use the retweets’ full text:
tweetL = api.user_timeline(id=2271808427, tweet_mode="extended")
# This is still truncated
tweetL[6].full_text
'RT @blawson_lcsw: So proud of these amazing @HSESchools students who presented their ideas on how to help their peers manage stress in mean…'
# Use retweeted_status to get the actual full text
tweetL[6].retweeted_status.full_text
'So proud of these amazing @HSESchools students who presented their ideas on how to help their peers manage stress in meaningful ways! Thanks @HSEPrincipal for giving us your time!'
This was tested with Python 3.6
and tweepy-3.6.0
.
I am using tweepy to fetch tweets from a user’s timeline using the script included here. However, the tweets are coming in truncated:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
new_tweets = api.user_timeline(screen_name = screen_name,count=200, full_text=True)
Returns:
Status(contributors=None,
truncated=True,
text=u"#Hungary's new bill allows the detention of asylum seekers
& push backs to #Serbia. We've seen push backs before sou2026 https://
t.co/iDswEs3qYR",
is_quote_status=False,
...
That is, for some i
, new_tweets[i].text.encode("utf-8")
appears like
#Hungary's new bill allows the detention of asylum seekers &
push backs to #Serbia. We've seen push backs before so…https://t.co/
iDswEs3qYR
Where the ...
in the latter replaces text that would normally be displayed on Twitter.
Does anyone know how I can override truncated=True
to get the full text on my request?
Instead of full_text=True you need tweet_mode=”extended”
Then, instead of text you should use full_text to get the full tweet text.
Your code should look like:
new_tweets = api.user_timeline(screen_name = screen_name,count=200, tweet_mode="extended")
Then in order to get the full tweets text:
tweets = [[tweet.full_text] for tweet in new_tweets]
Manolis’s answer is good but not complete. To get the extended version of a tweet (as in Manoli’s version), you would do :
tweetL = api.user_timeline(screen_name='sdrumm', tweet_mode="extended")
tweetL[8].full_text
'Statement of the day at #WholeChildSummit2019 - “‘SOME’ is not a number, and ‘SOON’ is not a time!” IMO, this is why educational systems get stuck. Who in your system will initiate change? TODAY! #HSEFutureReady'
However, if this tweet is a retweet, you’ll want to use the retweets’ full text:
tweetL = api.user_timeline(id=2271808427, tweet_mode="extended")
# This is still truncated
tweetL[6].full_text
'RT @blawson_lcsw: So proud of these amazing @HSESchools students who presented their ideas on how to help their peers manage stress in mean…'
# Use retweeted_status to get the actual full text
tweetL[6].retweeted_status.full_text
'So proud of these amazing @HSESchools students who presented their ideas on how to help their peers manage stress in meaningful ways! Thanks @HSEPrincipal for giving us your time!'
This was tested with Python 3.6
and tweepy-3.6.0
.