Sunday, November 02, 2014

A simple ruby twitter client

Install the gem

Proceed to install the required gem with gem install twitter as indicated at https://github.com/sferik/twitter.

Sample code

require "twitter" # include lib/gem

# set the configuration object with the application and access tokens provided by registering an app on twitter site
config = {
  consumer_key: 'YOUR_consumerkey', 
  consumer_secret: 'YOUR_consumersecret', 
  access_token: 'YOUR_accesstoken', 
  access_token_secret: 'YOUR_accesstokensecret'
}
client = Twitter::REST::Client.new(config) # instantiate the working object

client.update('Tweet from simple ruby client.') # execute a status update (a tweet)
# perform as many other operations you want with the client object, read the gem page (references) ...

References

No comments: