Search code examples
jsonpython-3.xtwittertweepy

How to get full tweet text?


Right now the line status.text is getting the tweet text but it is truncated (not the full tweet text). How can I get the full text of the tweet by using on status when getting information about tweets?

def on_status(self, status):

    if not hasattr(status,'retweeted_status'):

        #db = DatabaseInteractor.DatabaseInteractor()

        text=self.parse_text(status.text)
        created_at=self.parse_text(status.created_at)
        user_id=self.parse_text(status.user.id_str)
        username=self.parse_text(status.user.name)
        location=self.parse_text(status.user.location)
        coordinates=self.parse_text(status.coordinates)
        tweet_id=self.parse_text(status.id_str)
        hashtags=self.parse_text(status.entities['hashtags'])

        print("Created At: " + created_at)
        print("Tweet Text: "  + text)
        print("Tweet ID: " + tweet_id)
        print("Username: " + username)
        print("Username ID: " + user_id)
        print("Location: " + location )
        print("Coordinates: " + coordinates)
        print("Hashtags: " + hashtags)

Solution

  • It looks like you're using the Twitter Streaming API (statuses/filter, or a StreamListener in tweepy).

    In that case, if a Tweet has a field that states truncated: true, you need to look for an additional field in the Tweet object called extended_tweet, which will contain a field called full_text.

    The tweet_mode='extended' parameter suggested in the previous answer is not valid on the Streaming API.

    In Twitter Developer Labs (the next version of the API currently being tested) there is no longer a distincion between truncated or extended Tweets, and all Tweet objects will return the full text data.