light twitter web client in ruby on rails using oauth
Ruby JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
db/migrate
doc
public
script
test
vendor/gems
.gitignore
README.textile
Rakefile

README.textile

Lightwitter: Twitter OAuth API Example in Ruby on Rails

by Mark Bao

Here’s Lightwitter, an example for Twitter’s OAuth API authentication system in Ruby on Rails. Included herein are:

  • Authenticating to OAuth, with callback code.
  • Sample application that calls Twitter’s API REST endpoints with OAuth authentication.
  • An abstraction for the really huge default OAuth call, oauth_request
  • Abstractions for other OAuth and general stuff in application.rb: current_user, logged_in?, get_consumer, and access_token.
  • Documented code on what exactly is going on.

Prerequisites, and getting started

OAuth gem

First, you’ll need the OAuth gem (and the JSON gem if you don’t have it)

$ gem install oauth
$ gem install json

Configure databases, and migrate databases

Configure your databases in config/database.yml, and then migrate.

$ rake db:migrate

Specify your OAuth Consumer Keys in application.rb

Your keys can be found at the Twitter OAuth application manager page. Put these in the get_consumer method in app/controllers/application.rb. First consumer key, then consumer secret. It should look something like:

	# get_consumer establishes a OAuth consumer object
	def get_consumer
		# consumer key, consumer secret
		OAuth::Consumer.new("jaifCOie34LOLef93WTF32",
							"dfa5i2sjJZ245O2F45I23Dfje3ofJEO2I42FF35Q55",
							{ :site=>"http://twitter.com" })
	end

Uh, that’s about it!

Made it this far? You’re too legit to quit. Have fun.

License

For the lack of a consistent international agreement about what ‘public domain’ is, this work is licensed under the WTFPL (the Do What The F*** You Want To Public License) http://sam.zoy.org/wtfpl/

(And uh, dual licensed under the MIT license if such language doesn’t jive well with you/your employer.)