Twython,twi限制为140个字符

2024-04-25 07:25:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Tython在twitter中搜索,但是这个库似乎有140个字符的限制。有了python的新特性,即280个字符的长度,我们能做什么呢?在


Tags: twitter特性个字符试图用tython
2条回答

不幸的是,我找不到任何相关的“Tython”。但是,如果搜索twitter数据(在本例中是posts)和/或收集元数据是您的目标,那么我建议您查看一下库TwitterSearch。在

下面是一个快速的例子,它可以搜索包含单词GutenbergDoktorarbeit的Twitter帖子。在

from TwitterSearch import *
try:
    tso = TwitterSearchOrder() # create a TwitterSearchOrder object
    tso.set_keywords(['Guttenberg', 'Doktorarbeit']) # let's define all words we would like to have a look for
    tso.set_language('de') # we want to see German tweets only
    tso.set_include_entities(False) # and don't give us all those entity information

    # it's about time to create a TwitterSearch object with our secret tokens (API auth credentials)
    ts = TwitterSearch(
        consumer_key = 'aaabbb',
        consumer_secret = 'cccddd',
        access_token = '111222',
        access_token_secret = '333444'
     )

     # this is where the fun actually starts :)
    for tweet in ts.search_tweets_iterable(tso):
        print( '@%s tweeted: %s' % ( tweet['user']['screen_name'], tweet['text'] ) )
except TwitterSearchException as e: # take care of all those ugly errors if there are some
    print(e)

这不是特威森的限制。默认情况下,Twitter API返回旧的140个字符限制的tweet。要查看更新的扩展tweet,只需在搜索查询中提供以下参数:

tweet_mode=extended

然后,您将在返回tweet的full_text字段中找到280个字符的扩展tweet。在

我使用另一个库(TwitterAPI),但我认为您可以使用Twython执行以下操作:

results = api.search(q='pizza',tweet_mode='extended')
for result in results['statuses']:
    print(result['full_text'])

相关问题 更多 >

    热门问题