Getting full tweet text from “user_timeline” with tweepy

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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) 

Returns:

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,            ... 

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 

Where the ... in the latter replaces text that would normally be displayed on Twitter.

Does anyone know how I can override truncated=True to get the full text on my request?

回答1:

Instead of full_text=True you need tweet_mode="extended"

Then, instead of text you should use full_text to get the full tweet text.

Your code should look like:

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] for tweet in new_tweets]



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!