gpt4 book ai didi

python - tweepy:使用 tweet_mode ='extended' 时截断推文

转载 作者:太空狗 更新时间:2023-10-30 01:11:39 27 4
gpt4 key购买 nike

这是我的python代码

import tweepy
import csv

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

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

search_tweets = api.search('trump',count=1,tweet_mode='extended')
print(search_tweets[0].full_text)
print(search_tweets[0].id)

输出是下面的推文

RT @CREWcrew: When Ivanka Trump has business interests across the world, we have to 
ask if she’s representing the United States or her busi…
967462205561212929

虽然我使用了 tweet_mode='extended',但它被截断了。

如何提取全文??

最佳答案

我最近遇到了和你一样的问题,这只发生在转推上,我发现你可以在这里找到全文:tweet._json['retweeted_status']['full_text']

代码片段:

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

编辑 另外请注意,这不会在文本开头显示 RT @....,您可能想添加 RT 在文本的开头,任何适合你的。

编辑 2您可以获取推文作者的姓名并将其添加为开头,如下所示

retweet_text = 'RT @ ' + api.get_user(tweet.retweeted_status.user.id_str).screen_name

关于python - tweepy:使用 tweet_mode ='extended' 时截断推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48966176/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com