TwitterConnect
facebook connect style twitter oauth
Demo
http://twitter-connect.heroku.com
Install
sudo gem install twitter-connect
Usage
1 define config/twitter.yml
development:
consumer_token:
consumer_secret:
logout_url:
production:
consumer_token:
consumer_secret:
logout_url:
consumer_token and consumer_secret are fetched after you registered a twitter app. logout_url is where the app go to when user logs out or the session expired.
2 define routes
map.twitter_oauth '/twitter_oauth', :controller => 'twitter_connects', :action => 'oauth'
map.twitter_callback '/twitter_callback', :controller => 'twitter_connects', :action => 'callback'
map.twitter_logout '/twitter_logout', :controller => 'twitter_connects', :action => 'logout'
3 add javascript to html header
<%= javascript_include_tag 'twitter_connect' %>
4 add twitter login link on view page
<%= tc_login_button "window.location.reload()" %>
Or:
<%= tc_login_button "window.location.href = '#{tweets_path}'", :class_name => 'twitter_button' %>
tc_login_button
has two parameters, first is the callback javascript, second is customized parameter :text or :class_name
5 add twitter logout link on view page
<%= link_to "Logout from Twitter", twitter_logout_path %>
6 get twitter information or post tweet
class TwitterConnect < ApplicationController
include TwitterOauth
def tweet
oauth = get_oauth
client = Twitter::Base.new(oauth)
client.update('test')
end
end
Copyright (c) 2010 [Richard Huang], released under the MIT license