thefonso
thefonso

Reputation: 3390

twitter gem and passing user name and password

I'm using the twitter gem located here... http://rubydoc.info/gems/twitter/2.0.2

I'm trying to use a method that requires authentication... Twitter.home_timeline

The rdoc readme file at http://rubydoc.info/gems/twitter/2.0.2/file/README.md states...

Certain methods require authentication. To get your Twitter OAuth credentials, register an app at http://dev.twitter.com/apps

I have this file configured and set up...

Twitter.configure do |config|
  config.consumer_key = YOUR_CONSUMER_KEY
  config.consumer_secret = YOUR_CONSUMER_SECRET
  config.oauth_token = YOUR_OAUTH_TOKEN
  config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end

Now what I want, is for a user to come to my app, be able to enter their screen name and password and then see a display of their live stream and all sorts of cool twitter data on their user.

Please help... how do I do this? What method do I use to pass the website visitors username and password?

...ah yes, I am a rails noob so please be gentle.

Upvotes: 0

Views: 881

Answers (1)

iwasrobbed
iwasrobbed

Reputation: 46713

I think you are misunderstanding how this all works. The user never gives you their Twitter username/password. Here's what happens:

  1. User logs into your website
  2. User clicks the custom "Connect to Twitter" button that you create on your site (which is tied to an authentication gem like OmniAuth.. see this RailsCast for more info: http://railscasts.com/episodes/241-simple-omniauth)
  3. User is taken to Twitter where they login and (hopefully) grant you access to their info
  4. Twitter redirects the user back to your website and passes back a hash of important user data such as the access keys you need to get their information
  5. You save the relevant user information passed back from Twitter so you can access their information

Now that you went through those steps and you have the user's necessary access keys (i.e. the token and token secret), you can get their timeline info:

# Set all necessary auth info
Twitter.consumer_key = TWITTER_CONSUMER_KEY_GOES_HERE
Twitter.consumer_secret = TWITTER_CONSUMER_SECRET_GOES_HERE
Twitter.oauth_token = current_user.token
Twitter.oauth_token_secret = current_user.token_secret

# Get the most recent tweets from the Timeline
most_recent_tweets = Twitter.home_timeline

Upvotes: 5

Related Questions