Search code examples
pythontweepy

Python Tweepy 280 Character Statuses


I'm trying to scrape the full 280 character tweets off of twitter but I can't get them to not trail off with '...' after 140 chars. Here's my code:

import tweepy
import datetime

auth = tweepy.OAuthHandler("", "")
auth.set_access_token("", "")

api = tweepy.API(auth)

end_date = datetime.datetime.utcnow() - datetime.timedelta(days=0)
for status in api.user_timeline(targer_user):
    print(status.text)
    if status.created_at > end_date:
        break

I've read that adding text_mode=extendedto the function will solve this, but it's making no difference for me. If I use another suggested argument tweet_mode='extended', text is no longer an attribute of status.

How can I fix this?


Solution

  • It seems you need to use full_text now to get the 280 char tweet. Try something along the lines of:

    print(status.extended_tweet['full_text'])
    

    The tweet_mode='extended' can be used in user_timeline if you want, in which case you would just use below:

    print(status.full_text)
    

    This looks a bit nicer to me.

    It might also be worth pointing out that - from what I've read - this might not work for a retweet (Twitter streaming API not return full tweets) but there are separate bits of the api you can use for that, so be sure to check before you print.

    Twitter docs, in case you want a closer look at the update: https://developer.twitter.com/en/docs/tweets/tweet-updates.html