【问题标题】:Twython with 140 character limitation of twitter推特 140 个字符限制的 Twython
【发布时间】:2017-11-20 11:34:37
【问题描述】:

我正在尝试使用 Tython 在 twitter 中进行搜索,但该库似乎对 140 个字符有限制。有了python的新特性,即280个字符的长度,可以做什么?

【问题讨论】:

    标签: python twitter web-scraping social-networking twython


    【解决方案1】:

    这不是 Twython 的限制。 Twitter API 默认返回旧的 140 个字符的有限推文。为了查看更新的扩展推文,您只需将此参数提供给您的搜索查询:

    tweet_mode=extended

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

    我使用另一个库 (TwitterAPI),但我认为您会使用 Twython 做这样的事情:

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

    【讨论】:

    • 不,它也适用于 RT。 RT 作为整个推文对象嵌入retweeted_statusus 字段中。因此,您还将在 full_text 字段中找到此对象中的 280 个字符的文本。
    【解决方案2】:

    很遗憾,我找不到任何与“Tython”相关的内容。但是,如果搜索 twitter 数据(在本例中为帖子)和/或收集元数据是您的目标,我建议您查看库 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)
    

    【讨论】:

      猜你喜欢
      • 2021-01-16
      • 2016-05-29
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多