Follow the below steps to create Twitter application for your rails application:
1. Goto https://dev.twitter.com/
2. Click “Create an App” link.
3. Enter your app name, description, website and call back url.
For Website and call back url enter “http://127.0.0.1:3000/” for local host or your application url say “http://www.twitterapp.com”
5. You will get the Consumer key and Consumer secret.
Follow the below steps to integrate the Twitter login:
1. Include the below in your Gemfile.
gem “omniauth-twitter”
2. Execute the below command to install the gem
bundle
3. Create a new file called “omniauth.rb” in your initializers folder(app/config/initializers)
4. Inside the “omniauth.rb” copy the below lines
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ‘YOUR APP CONSUMER KEY’, ‘YOUR APP CONSUMER SECRET’
end
5. Paste the below lines to your routes file
#calback url from twitter
match ‘/auth/:provider/callback’ => ‘users#twitter_login’
6. Paste the below lines to your users controller
def twitter_login
omniauth = request.env[‘omniauth.auth’] # This contains all the details of the user say Email, Name, Age so that you can store it in your application db.
redirect_to “Your redirect path after user logged in”
end
7. Paste the below line to your view file where you want to display the Login with facebook link, Say in your users/new.html.erb
<a href=”/auth/twitter”>Login Via Twitter</a>
8. Restart the Server
9. Go to http://localhost:3000/users/new
10. Click the link “Login Via Twitter” , page will be redirected to the Twitter site then redirected to your home page.
1. Goto https://dev.twitter.com/
2. Click “Create an App” link.
3. Enter your app name, description, website and call back url.
For Website and call back url enter “http://127.0.0.1:3000/” for local host or your application url say “http://www.twitterapp.com”
5. You will get the Consumer key and Consumer secret.
Follow the below steps to integrate the Twitter login:
1. Include the below in your Gemfile.
gem “omniauth-twitter”
2. Execute the below command to install the gem
bundle
3. Create a new file called “omniauth.rb” in your initializers folder(app/config/initializers)
4. Inside the “omniauth.rb” copy the below lines
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ‘YOUR APP CONSUMER KEY’, ‘YOUR APP CONSUMER SECRET’
end
5. Paste the below lines to your routes file
#calback url from twitter
match ‘/auth/:provider/callback’ => ‘users#twitter_login’
6. Paste the below lines to your users controller
def twitter_login
omniauth = request.env[‘omniauth.auth’] # This contains all the details of the user say Email, Name, Age so that you can store it in your application db.
redirect_to “Your redirect path after user logged in”
end
7. Paste the below line to your view file where you want to display the Login with facebook link, Say in your users/new.html.erb
<a href=”/auth/twitter”>Login Via Twitter</a>
8. Restart the Server
9. Go to http://localhost:3000/users/new
10. Click the link “Login Via Twitter” , page will be redirected to the Twitter site then redirected to your home page.
No comments:
Post a Comment