Created
March 20, 2013 05:28
-
-
Save lxyuma/5202528 to your computer and use it in GitHub Desktop.
ruby omniauth twitter feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# omniauth + omniauth-twitter gems are required | |
class TwitterApi | |
SITE = "http://api.twitter.com" | |
API_URL = { :update_status => SITE + "/1.1/statuses/update.json"} | |
def self.feed | |
access_token = official_access_token | |
response = access_token.request(:post, | |
API_URL[:update_status], | |
{"status" => "hello twitter"}) | |
end | |
private | |
def self.access_token(token, secret) | |
consumer = OAuth::Consumer.new( | |
Rails.application.config.twitter_consumer_key, | |
Rails.application.config.twitter_consumer_secret, | |
{ :site => SITE }) | |
return OAuth::AccessToken.new(consumer, token, secret) | |
end | |
def self.official_access_token | |
access_token(Rails.application.config.twitter_access_token, | |
Rails.application.config.twitter_access_token_secret) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment