simple twitter gem tutorial

to use twitter gem with rails, is quite simple.

install it by sudo gem install twitter

in environment.rb add config.gem 'twitter'

to authenticate user with twitter
httpauth = Twitter::HTTPAuth.new('twitter_email@example.com','twitter_password')
twitter = Twitter::Base.new( httpauth )

after that you can fetch your timeline and pass it to the view

@twitter = twitter.user_timeline :count => 5

and loop it in the view by
<ul>
<% for tweet in @twitter %>
<li><%= tweet.text%></li>
<% end %>
</ul>

Thats All. Thank You

Advertisements

One thought on “simple twitter gem tutorial

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s