从“user_timeline"获取完整的推文文本与 tweepy [英] Getting full tweet text from "user_timeline" with tweepy
问题描述
我正在使用 tweepy 使用 此处 中包含的脚本从用户的时间线中获取推文.但是,推文被截断了:
I am using tweepy to fetch tweets from a user's timeline using the script included here. However, the tweets are coming in truncated:
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")
看起来像
That is, for some i
, new_tweets[i].text.encode("utf-8")
appears like
#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 上显示的文本.
Where the ...
in the latter replaces text that would normally be displayed on Twitter.
有谁知道我如何覆盖 truncated=True
以获取我请求的全文?
Does anyone know how I can override truncated=True
to get the full text on my request?
推荐答案
代替 full_text=True 你需要 tweet_mode="extended"
Instead of full_text=True you need tweet_mode="extended"
然后,您应该使用 full_text 而不是 text 来获取完整的推文文本.
Then, instead of text you should use full_text to get the full tweet text.
您的代码应如下所示:
new_tweets = api.user_timeline(screen_name = screen_name,count=200, tweet_mode="extended")
然后为了获得完整的推文文本:
Then in order to get the full tweets text:
tweets = [[tweet.full_text] 用于 new_tweets 中的推文]
这篇关于从“user_timeline"获取完整的推文文本与 tweepy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!