【问题标题】:Fetch tweets based on hashtag and date range根据主题标签和日期范围获取推文
【发布时间】:2018-07-18 10:45:33
【问题描述】:

我想获取上个月内带有特定主题标签的推文中的所有图像。我目前正在使用 Ruby。在我的index.rb 文件中,我试图将以下代码存储在一个变量中:

@photos = client.search('#bestfriends', { include_entities: true, fromDate:"201801071200>",toDate:"201802071200", include_entities: true })

但是,当我在命令行上运行它时,我得到以下信息:

{:statuses=>
    [{:created_at=>"Thu Feb 08 00:15:10 +0000 2018",
      :id=>961392929762938880,
      :id_str=>"961392929762938880",
      :text=>
       "FCC Says Releasing 'Jokes' It Wrote About Ajit Pai Illegally Colluding With Verizon (WHICH HAPPENED) Would 'Harm' A… ",
      :truncated=>true,
      :entities=>
       {:hashtags=>[],
        :symbols=>[],
        :user_mentions=>[],
        :urls=>

正如您从:hashtags=>[], 中看到的那样,标签是空的,我有办法根据日期范围内的标签获取推文吗?我正在使用https://github.com/sferik/twitter,但不知道使用https://github.com/twitter/twurl 是否更好,因为它来自命令行。

【问题讨论】:

  • 这表示“截断:true”,因此您需要使用 tweet_mode=extended 参数来检索包括任何实体在内的完整 Tweet 对象。
  • 我是否在查询中添加tweet_mode=extended @AndyPiper?我的意思是这样的:client.search('#bestfriends', { tweet_mode: extended, include_entities: true, fromDate:"201801071200>",toDate:"201802071200", include_entities: true })
  • 应该可以,但我不熟悉您直接使用的库。
  • @AndyPiper 你能嵌套查询吗?意思是如果我想检查:entities:urls 是否为空?

标签: ruby api twitter


【解决方案1】:

您要查找的过滤器是 has:hashtags,但不幸的是,它仅在高级和企业搜索中可用。

https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html

因此,除非您将应用升级到高级版,否则任何库都不会直接返回您想要的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 2019-06-22
    • 2016-10-27
    • 1970-01-01
    • 2021-08-01
    • 2013-09-24
    • 1970-01-01
    相关资源
    最近更新 更多