简体   繁体   English

在 Python 中使用 tweepy 删除了长推文消息

[英]Long tweet message got cut using tweepy in Python

I noticed that using the below code, I cannot retrieve the long tweet;我注意到使用下面的代码,我无法检索到长推文; somehow it got cut.不知何故它被切断了。 Can anyone suggest a way to retrieve the full tweet message?谁能建议一种检索完整推文消息的方法?

tweets = []

#for month in range(8,13,1):
for i,j in zip(start_time,end_time):
    print(i)
    print(j)
    for response in tweepy.Paginator(client.search_all_tweets, 
                                     query = 'สมอง -is:retweet lang:th',
                                     user_fields = ['username', 'public_metrics', 'description', 'location'],
                                     tweet_fields = ['created_at', 'geo', 'public_metrics', 'text'],
                                     expansions = ['author_id', 'geo.place_id'],
                                     start_time = i,
                                     end_time = j):
                                     #max_results=500):
        time.sleep(1)
        tweets.append(response)

I'm unable to reproduce your snippet since I don't have the credentials but can you try something like this:我无法重现您的代码段,因为我没有凭据,但您可以尝试这样的操作吗:

import tweepy

client = tweepy.Client("paste your token")

query = 'สมอง -is:retweet lang:th'
tweets = tweepy.Paginator(client.search_recent_tweets, query=query,
                        user_fields = ['username', 'public_metrics', 'description', 'location'],
                        tweet_fields=['created_at', 'geo', 'public_metrics', 'text'],
                        max_results=100).flatten(limit=1000)

for tweet in tweets:
    print(tweet.text)  ## this should give you the full tweet

Please note to change the respective search method ( search_all_tweets ).请注意更改相应的搜索方法 ( search_all_tweets )。 I couldn't use it since it was asking for credentials for v2.我无法使用它,因为它要求提供 v2 的凭据。 You can also get rid of the flatten if you don't want only the data part of your tweet.如果您不想要推文的数据部分,您也可以去掉flatten

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM