Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Twitter4R OAuth

1,984 views

Published on

Published in: Technology
  • Be the first to comment

Twitter4R OAuth

  1. 1. Configuring your Twitter4R App with OAuth Susan Potter (@SusanPotter) Twitter4R (@t4ruby) March 2011
  2. 2. OAuth. . . • sucks to configure • but it is better than users passing 3rd party apps their clear passwords • 3rd party apps don’t need to store passwords that are decryptable
  3. 3. OAuth. . . • sucks to configure • but it is better than users passing 3rd party apps their clear passwords • 3rd party apps don’t need to store passwords that are decryptable
  4. 4. OAuth. . . • sucks to configure • but it is better than users passing 3rd party apps their clear passwords • 3rd party apps don’t need to store passwords that are decryptable
  5. 5. In this screencast we will. . . • set up a new Twitter app https://twitter.com/apps/new • configure consumer tokens every app has a key and a secret; secret should be ’secret’ • getting access tokens for user apps need to retrieve access tokens for each user • use access tokens store access tokens (key and secret) for each user
  6. 6. In this screencast we will. . . • set up a new Twitter app https://twitter.com/apps/new • configure consumer tokens every app has a key and a secret; secret should be ’secret’ • getting access tokens for user apps need to retrieve access tokens for each user • use access tokens store access tokens (key and secret) for each user
  7. 7. In this screencast we will. . . • set up a new Twitter app https://twitter.com/apps/new • configure consumer tokens every app has a key and a secret; secret should be ’secret’ • getting access tokens for user apps need to retrieve access tokens for each user • use access tokens store access tokens (key and secret) for each user
  8. 8. In this screencast we will. . . • set up a new Twitter app https://twitter.com/apps/new • configure consumer tokens every app has a key and a secret; secret should be ’secret’ • getting access tokens for user apps need to retrieve access tokens for each user • use access tokens store access tokens (key and secret) for each user
  9. 9. Setting up a new Twitter app • Go to twitter.com • Login to your account • Fill in form at twitter.com/apps/new • Copy consumer tokens
  10. 10. Setting up a new Twitter app • Go to twitter.com • Login to your account • Fill in form at twitter.com/apps/new • Copy consumer tokens
  11. 11. Setting up a new Twitter app • Go to twitter.com • Login to your account • Fill in form at twitter.com/apps/new • Copy consumer tokens
  12. 12. Setting up a new Twitter app • Go to twitter.com • Login to your account • Fill in form at twitter.com/apps/new • Copy consumer tokens
  13. 13. Configuring consumer tokens # In a Rails 2.3 / 3.x app this might be # in: config/initializers/twitter4r.rb Twitter Client.configure do |config| config.oauth_consumer_token = CONSUMER_KEY config.oauth_consumer_secret = CONSUMER_SECRET end
  14. 14. Configuring consumer tokens # In a Rails 2.3 / 3.x app this might be # in: config/initializers/twitter4r.rb Twitter Client.configure do |config| config.oauth_consumer_token = CONSUMER_KEY config.oauth_consumer_secret = CONSUMER_SECRET end
  15. 15. Configuring consumer tokens # In a Rails 2.3 / 3.x app this might be # in: config/initializers/twitter4r.rb Twitter Client.configure do |config| config.oauth_consumer_token = CONSUMER_KEY config.oauth_consumer_secret = CONSUMER_SECRET end
  16. 16. Configuring consumer tokens # In a Rails 2.3 / 3.x app this might be # in: config/initializers/twitter4r.rb Twitter Client.configure do |config| config.oauth_consumer_token = CONSUMER_KEY config.oauth_consumer_secret = CONSUMER_SECRET end
  17. 17. Getting access tokens for a user, [1/2] # Using OAuth Ruby gem library helper in: # app/controller/application_controller.rb def redirect_to_twitter consumer = OAuth Consumer.new KEY, SECRET, :site => “https://twitter.com” token = consumer.get_request_token redirect_to(token.authorize_url) end
  18. 18. Getting access tokens for a user, [1/2] # Using OAuth Ruby gem library helper in: # app/controller/application_controller.rb def redirect_to_twitter consumer = OAuth Consumer.new KEY, SECRET, :site => “https://twitter.com” token = consumer.get_request_token redirect_to(token.authorize_url) end
  19. 19. Getting access tokens for a user, [1/2] # Using OAuth Ruby gem library helper in: # app/controller/application_controller.rb def redirect_to_twitter consumer = OAuth Consumer.new KEY, SECRET, :site => “https://twitter.com” token = consumer.get_request_token redirect_to(token.authorize_url) end
  20. 20. Getting access tokens for a user, [1/2] # Using OAuth Ruby gem library helper in: # app/controller/application_controller.rb def redirect_to_twitter consumer = OAuth Consumer.new KEY, SECRET, :site => “https://twitter.com” token = consumer.get_request_token redirect_to(token.authorize_url) end
  21. 21. Getting access tokens for a user, [2/2] # Using OAuth Ruby gem library in: # app/controller/oauth_controller.rb def create provider = params[:provider] case provider when ’twitter’ # bla bla bla end end # Remember to add the routes: match ’oauth/:provider/callback’ => ’oauth#create’
  22. 22. Getting access tokens for a user, [2/2] # Using OAuth Ruby gem library in: # app/controller/oauth_controller.rb def create provider = params[:provider] case provider when ’twitter’ # bla bla bla end end # Remember to add the routes: match ’oauth/:provider/callback’ => ’oauth#create’
  23. 23. Getting access tokens for a user, [2/2] # Using OAuth Ruby gem library in: # app/controller/oauth_controller.rb def create provider = params[:provider] case provider when ’twitter’ # bla bla bla end end # Remember to add the routes: match ’oauth/:provider/callback’ => ’oauth#create’
  24. 24. Using access tokens # Pass in access key/secret tokens to # Twitter Client.new call for each user client = Twitter Client.new :oauth_access => { :key => ACCESS_KEY, :secret => ACCESS_SECRET } client.status(:post, “Tweet from my OAuth-ed app”)
  25. 25. Using access tokens # Pass in access key/secret tokens to # Twitter Client.new call for each user client = Twitter Client.new :oauth_access => { :key => ACCESS_KEY, :secret => ACCESS_SECRET } client.status(:post, “Tweet from my OAuth-ed app”)
  26. 26. Using access tokens # Pass in access key/secret tokens to # Twitter Client.new call for each user client = Twitter Client.new :oauth_access => { :key => ACCESS_KEY, :secret => ACCESS_SECRET } client.status(:post, “Tweet from my OAuth-ed app”)
  27. 27. Fin HTH, if you have more questions: twitter4r-users@googlegroups.com
  28. 28. Fin HTH, if you have more questions: twitter4r-users@googlegroups.com

×