Home:ALL Converter>Get the last tweet with tweepy

Get the last tweet with tweepy

Ask Time:2015-08-15T16:11:59         Author:Louis Etienne

Json Formatter

I'm trying to have the last tweet of the user with Tweepy. This is my code :

class Bot:
    def __init__(self, keys):
        self._consumer_key = keys[0]
        self._consumer_secret = keys[1]
        self._access_token = keys[2]
        self._access_secret = keys[3]

        try:
            auth = tweepy.OAuthHandler(self._consumer_key,
                                       self._consumer_secret)
            auth.set_access_token(self._access_token, self._access_secret)

            self.client = tweepy.API(auth)
            if not self.client.verify_credentials():
                raise tweepy.TweepError
        except tweepy.TweepError as e:
            print('ERROR : connection failed. Check your OAuth keys.')
        else:
            print('Connected as @{}, you can start to tweet !'.format(self.client.me().screen_name))
            self.client_id = self.client.me().id


    def get_last_tweet(self):
        tweet = self.client.user_timeline(id = self.client_id, count = 1)
        print(tweet.text)
        # AttributeError: 'ResultSet' object has no attribute 'text' . 

I understand the error, but how can I have the text from a status?

Author:Louis Etienne,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32022845/get-the-last-tweet-with-tweepy
yy