Created
May 28, 2010 18:22
-
-
Save kerskine/417519 to your computer and use it in GitHub Desktop.
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
module TwitterOAuth | |
class Client | |
def initialize(options = {}) | |
@consumer_key = options[:consumer_key] | |
@consumer_secret = options[:consumer_secret] | |
@token = options[:token] | |
@secret = options[:secret] | |
end | |
def authorize(token, secret, options = {}) | |
request_token = OAuth::RequestToken.new( | |
consumer, token, secret | |
) | |
@access_token = request_token.get_access_token(options) | |
@token = @access_token.token | |
@secret = @access_token.secret | |
@access_token | |
end |
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
class TweetersController < ApplicationController | |
require 'rubygems' | |
require 'twitter_oauth' | |
def index | |
end | |
def auth | |
@client = TwitterOAuth::Client.new(:consumer_key => 'NNN', :consumer_secret => 'NNNNNN') | |
request_token = @client.request_token(:oauth_callback => 'http://0.0.0.0:3000/success') | |
session[:request_token] = request_token.token | |
session[:request_token_secret] = request_token.secret | |
redirect_to request_token.authorize_url | |
end | |
def success | |
@access_token = @client.authorize(session[:request_token], session[:request_token_secret], :oauth_verifier => params[:oauth_verifier]) | |
if @client.authorized? | |
@client.update('checking out the twitter_oauth library') # sends a twitter status update | |
else | |
redirect_to "/" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment