tweepy: truncated tweets when using tweet_mode='extended'

前端 未结 2 1254
-上瘾入骨i
-上瘾入骨i 2021-01-03 04:23

This is my code in python

import tweepy
import csv

consumer_key = \"?\"
consumer_secret = \"?\"
access_token = \"?\"
access_token_secret = \"?\"

auth = twe         


        
相关标签:
2条回答
  • 2021-01-03 04:35

    I've had the same problem as you recently, this happened for the retweets only, I found that you can find the full text under here: tweet._json['retweeted_status']['full_text']

    Code snippet:

    ...
    search_tweets = api.search('trump',count=1,tweet_mode='extended')
    for tweet in search_tweets:
        if 'retweeted_status' in tweet._json:
            print(tweet._json['retweeted_status']['full_text'])
        else:
            print(tweet.full_text)
    ...
    

    EDIT Also please note that this won't show RT @.... at the beginning of the text, you might wanna add RT at the start of the text, whatever suits you.

    EDIT 2 You can get the name of the author of the tweet and add it as the beginning as follows

    retweet_text = 'RT @ ' + api.get_user(tweet.retweeted_status.user.id_str).screen_name
    
    0 讨论(0)
  • 2021-01-03 04:40

    This worked for me :

    if 'retweeted_status' in status._json:
       if 'extended_tweet' in status._json['retweeted_status']:
          text = 'RT @'+status._json['retweeted_status']['user']['screen_name']+':'+status._json['retweeted_status']['extended_tweet']['full_text']
       else:
          text = 'RT @'+status._json['retweeted_status']['user']['screen_name']+':' +status._json['retweeted_status']['text']
    else:
       if 'extended_tweet' in status._json:
          text = status._json['extended_tweet']['full_text']
       else:
          text = status.text
    
    0 讨论(0)
提交回复
热议问题