想使用 Twitter api 的关键字洞察每天获取关键字的推文数量

want to get number of tweets of a keyword per a day using Keyword Insights of Twitter api

我想获取每天某个关键字的推文数量。

我想通过 Ruby 使用 Twitter api 的关键字洞察。 : https://developer.twitter.com/en/docs/ads/audiences/api-reference/keyword-insights

我试过写代码。但是我得到了这样的错误。

`<main>': undefined method `keywords' for #<Twitter::REST::Client:0x00000000062837b8> (NoMethodError)

Ruby 代码如下。

require "twitter"
require 'yaml'

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
Encoding.default_external = 'UTF-8'

  @client = Twitter::REST::Client.new do |config|
    config.consumer_key        = 'xxxx'
    config.consumer_secret     = 'xxxx'
    config.access_token        = 'xxxx-xxxx'
    config.access_token_secret = 'xxxx'
  end

# @client.update('hoge')
# => succes.
@client.insights.keywords.search("DAY","Ruby")

我该怎么办?

Ruby twitter gem 没有任何检索见解的方法(已在文档中查看)。您可以按照推特 api 参考实现自己的方法:https://developer.twitter.com/en/docs/ads/audiences/api-reference/insights

正如另一位发帖人提到的,twitter gem 中没有广告 API 支持,但 Twitter 有 twitter-ads gem,您可以 obtain on Github. Note that you will also need to have your app tokens whitelisted for access to the Ads API. You can apply for that via Twitter's developer site.