skip to Main Content

I want to get number of tweets of a keyword per a day.

I want to use Keyword Insights of Twitter api using Ruby. : https://developer.twitter.com/en/docs/ads/audiences/api-reference/keyword-insights

I have tryed to write code. But I got such following error.

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

The Ruby code is following.

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")

What should I do?

2

Answers


  1. Ruby twitter gem doesn’t has any method to retrieve insights (checked on documentation). You can implement your own method following the twitter api reference: https://developer.twitter.com/en/docs/ads/audiences/api-reference/insights

    Login or Signup to reply.
  2. As the other poster mentioned, there’s no Ads API support in the twitter gem, but Twitter has a twitter-ads gem you can 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search