Comments (6)
参考にするブログ
from twatcher.
今回行うプロセス
- Twitter developerへ登録
- 各API keyを取得
- gem Twitterを導入
- Jobを追加する
from twatcher.
1.Twitter developerへ登録
開発者登録を以下を参考に行う
from twatcher.
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.
3. gem Twitterを導入
- Gemfileに
gem 'twitter', '~> 5.14'
を導入する - Macのターミナルで
bundle install
を実行する
from twatcher.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twatcher.