0.01
No commit activity in last 3 years
No release in over 3 years
facebook connect style twitter oauth
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

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