LoginSignup
2
2

More than 5 years have passed since last update.

call Twitter API with rubytter

Posted at

this example is using pit.

#!/usr/bin/env ruby
require 'pit'
require 'oauth'
require 'rubytter'

config = Pit.get('twitter.com', require: {
                   'consumer_key'        => '',
                   'consumer_secret'     => '',
                   'access_token'        => '',
                   'access_token_secret' => '',
                 })
consumer = OAuth::Consumer.new(config['consumer_key'], config['consumer_secret'], :site => 'https://api.twitter.com')
token = OAuth::AccessToken.new(consumer, config['access_token'], config['access_token_secret'])
client = OAuthRubytter.new(token)

profile = client.verify_credentials
client.user_timeline(profile.id, { count: 50, include_rts: true }).each do |tweet|
  puts "#{ tweet.created_at } - #{ tweet.text.gsub(/\n/, ' ') }"
end
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2