[英]Getting full tweet text from “user_timeline” with 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)
返回:
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,
...
也就是說,對於某些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
后者中的...
替換通常在Twitter上顯示的文本。
有誰知道如何覆蓋truncated=True
以獲取我的請求的全文?
而不是full_text = True,你需要tweet_mode =“extended”
然后,您應該使用full_text來獲取完整的推文文本,而不是文本。
您的代碼應如下所示:
new_tweets = api.user_timeline(screen_name = screen_name,count=200, tweet_mode="extended")
然后為了獲得完整的推文文字:
tweets = [[tweet.full_text] for tweet in new_tweets]
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'
但是,如果此推文是轉發,您將需要使用轉推的全文:
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!'
這是使用Python 3.6
和tweepy-3.6.0
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.