Showing posts with label Twitter. Show all posts
Showing posts with label Twitter. Show all posts

Thursday, January 28, 2016

Ruby: Tweeting Using OAuth gem

Package needed:

gem install oauth

Ruby script: tweet.rb

require 'json'
require 'oauth'

consumer_key = '' # Your consumer key
consumer_secret = '' # Your consumer secret
access_token = '' # Your access token
access_token_secret = '' # Your access token secret

consumer = OAuth::Consumer.new(
consumer_key,
consumer_secret,
site:'https://api.twitter.com/'
)
endpoint = OAuth::AccessToken.new(consumer, access_token, access_token_secret)

# STATUS
status = ARGV[0]

# POST
response = endpoint.post('https://api.twitter.com/1.1/statuses/update.json', status: status )
result = JSON.parse(response.body)



Execute the ruby script:

ruby ./tweet.rb "Good morning! (おはようございます。)"