【问题标题】:Twython Twitter Post is TruncatedTwython Twitter 帖子被截断
【发布时间】:2020-08-02 19:44:13
【问题描述】:

我正在尝试使用 Twython 获取一些推文,但即使使用 tweet_mode:extended 结果仍然会被截断。任何想法我如何才能获得全文。

def requestTweets(topic, resultType = "new", amount = 10, language = "en"):
'''Get the n tweets for a topic, either newest (new) or most popular (popular)'''
#Create Query
query = {'q': topic,
        'result_type': resultType,
        'count': amount,
        'lang': language,
        'tweet_mode': 'extended',
        }

#Get Data
dict_ = {'user': [], 'date': [], 'full_text': [],'favorite_count': []}
for status in python_tweets.search(**query)['statuses']:
    dict_['user'].append(status['user']['screen_name'])
    dict_['date'].append(status['created_at'])
    dict_['full_text'].append(status['full_text'])
    dict_['favorite_count'].append(status['favorite_count'])

# Structure data in a pandas DataFrame for easier manipulation
df = pd.DataFrame(dict_)
df.sort_values(by='favorite_count', inplace=True, ascending=False)
return df

tweets = requestTweets("chocolate")
for index, tweet in tweets.iterrows():
    print("***********************************")
    print(tweet['full_text'])

结果如下所示:

【问题讨论】:

  • 你能检查 Twython 中的“截断”参数吗?如果是真的,我建议你使用不同的包。我对 Twython 和 Twitter API 的限制有一些问题(这就是我使用下面建议的包的原因)。

标签: python twitter twython twitterapi-python


【解决方案1】:

我知道有点晚了!但我把答案告诉了谁可能需要它。

我正在使用 twython==3.9.1,它可以使用以下 sn-p 代码获取推文的全文:

twython: Twython
tweets = twython.get_user_timeline(
        screen_name=user_screen_name, # or user id
        count=200, #  max count is 200
        include_retweets=include_retweets, # could be False or True
        exclude_replies=exclude_replies, # could be False or True
        tweet_mode='extended', # to get tweets full text
    )

【讨论】:

    【解决方案2】:

    我找不到使用 Twython 的方法,所以最后我改用了 tweepy,不过,如果有人有答案,那就太好了。

    【讨论】:

      猜你喜欢
      • 2010-12-07
      • 2012-09-09
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 2015-11-24
      • 2012-06-16
      • 1970-01-01
      相关资源
      最近更新 更多