通过tweepy从"user_timeline"获取完整的推文文本

atk*_*t12 17 python twitter tweepy

我使用tweepy使用此处包含的脚本从用户的时间线获取推文.但是,这些推文正在被截断:

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
new_tweets = api.user_timeline(screen_name = screen_name,count=200, full_text=True)
Run Code Online (Sandbox Code Playgroud)

返回:

Status(contributors=None, 
     truncated=True, 
     text=u"#Hungary's new bill allows the detention of asylum seekers 
          & push backs to #Serbia. We've seen push backs before so\u2026 https:// 
          t.co/iDswEs3qYR", 
          is_quote_status=False, 
          ...
Run Code Online (Sandbox Code Playgroud)

也就是说,对某些人来说i,new_tweets[i].text.encode("utf-8")似乎是

#Hungary's new bill allows the detention of asylum seekers & 
push backs to #Serbia. We've seen push backs before so…https://t.co/
iDswEs3qYR
Run Code Online (Sandbox Code Playgroud)

...在这通常会在Twitter上显示后更换文本.

有谁知道如何覆盖truncated=True我的请求获取全文?

Man*_*kis 22

而不是full_text = True,你需要tweet_mode ="extended"

然后,您应该使用full_text来获取完整的推文文本,而不是文本.

您的代码应如下所示:

new_tweets = api.user_timeline(screen_name = screen_name,count=200, tweet_mode="extended")
Run Code Online (Sandbox Code Playgroud)

然后为了获得完整的推文文字:

tweets = [[tweet.full_text] for tweet in new_tweets]

  • 它不适用于我的情况。我仍然收到被截断的推文。:( (2认同)

irr*_*rom 10

Manolis 的回答很好,但并不完整。要获得推文的扩展版本(如 Manoli 的版本),您可以执行以下操作:

tweetL = api.user_timeline(screen_name='sdrumm', tweet_mode="extended")
tweetL[8].full_text
'Statement of the day at #WholeChildSummit2019 - “‘SOME’ is not a number, and ‘SOON’ is not a time!” IMO, this is why educational systems get stuck. Who in your system will initiate change? TODAY! #HSEFutureReady'
Run Code Online (Sandbox Code Playgroud)

但是,如果此推文是转推,则您需要使用转推的全文:

tweetL = api.user_timeline(id=2271808427, tweet_mode="extended")
# This is still truncated
tweetL[6].full_text
'RT @blawson_lcsw: So proud of these amazing @HSESchools students who presented their ideas on how to help their peers manage stress in mean…'
# Use retweeted_status to get the actual full text
tweetL[6].retweeted_status.full_text
'So proud of these amazing @HSESchools students who presented their ideas on how to help their peers manage stress in meaningful ways! Thanks @HSEPrincipal for giving us your time!'
Run Code Online (Sandbox Code Playgroud)

这是用Python 3.6和测试的tweepy-3.6.0