Giter VIP home page Giter VIP logo

Comments (6)

sotanengel avatar sotanengel commented on July 20, 2024

参考にするブログ

from twatcher.

sotanengel avatar sotanengel commented on July 20, 2024

今回行うプロセス

  1. Twitter developerへ登録
  2. 各API keyを取得
  3. gem Twitterを導入
  4. Jobを追加する

from twatcher.

sotanengel avatar sotanengel commented on July 20, 2024

1.Twitter developerへ登録

開発者登録を以下を参考に行う

from twatcher.

sotanengel avatar sotanengel commented on July 20, 2024

2.各API keyを取得

GemfileにRubyのTwitterライブラリをインストールする。

Gemfileに追加したコマンド

# Twitter Get library. Read more: https://github.com/sferik/twitter
gem 'http-parser', '~> 1.2', '>= 1.2.3'
gem 'twitter', '~> 5.14'

from twatcher.

sotanengel avatar sotanengel commented on July 20, 2024

3. gem Twitterを導入

  • Gemfileにgem 'twitter', '~> 5.14'を導入する
  • Macのターミナルでbundle installを実行する

from twatcher.

sotanengel avatar sotanengel commented on July 20, 2024

4. Jobを追加する

  • rails generate job get_twitter_trends_jobをコマンドラインで実行してTwitterのトレンドを取得するActive Jobを追加する。
  • 以下の内容をget_twitter_trends_job.rb追加する。
class GetTwitterTrendsJob < ApplicationJob
  queue_as :default
  def get()
    client = Twitter::REST::Client.new do |config|
      config.consumer_key        = ENV["TWITTER_API_KEY"]
      config.consumer_secret     = ENV["TWITTER_API_SECRET_KEY"]
      config.access_token        = ENV["TWITTER_ACCESS_TOKEN"]
      config.access_token_secret = ENV["TWITTER_ACCESS_SECRET_TOKEN"]
    end
    @trends = client.trends(id = 23424856).attrs[:trends].first(10)
  end
end

from twatcher.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.