如何从Tweepy获取一条推文的全文

时间:2018-12-04 18:40:57

标签: python twitter tweepy

我正在使用Tweepy通过字符串查询推文,当我这样做时,它会以截断的方式返回推文,例如“快速棕狐狸...”。

如何获取推文的全文?

这是我的代码的一部分

def get_tweets(self, query, count = 10):

    #this is main function that will query for 
    #a specified number of tweets

    #an empty list to store parsed tweets
    tweets = []

    a = self.api.get_status(912886007451676672, tweet_mode='extended')

    try:
        #call the api to fetch tweets
        fetched = self.api.search(q = query, rpp = int(count), tweet_mode="extended")

        #parsing tweets one by one
        for tweet in fetched:
            #empty dictionary to store required params of a tweet
            parsed_tweet = {}

            #saving text of tweet in dictionary
            parsed_tweet['text'] = self.api.get_status(tweet.id, tweet_mode='extended')._json['full_text']
            #saving the sentiments of the tweet
            parsed_tweet['sentiment'] = self.get_tweet_sentiment(tweet.full_text)
            parsed_tweet['subjectivity'] = self.get_tweet_subjectivity(tweet.full_text)
            #appending parsed tweet to tweets list
            #and only append once if there are rebtweets
            if tweet.retweet_count > 0:
                if parsed_tweet not in tweets:
                    tweets.append(parsed_tweet)
            else:
                tweets.append(parsed_tweet)

        return tweets

    except tweepy.TweepError as e:
        print("Error : " + str(e))

1 个答案:

答案 0 :(得分:0)

在扩展模式下使用full_text属性