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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Fin
HTH, if you have more questions:
twitter4r-users@googlegroups.com
28. Fin
HTH, if you have more questions:
twitter4r-users@googlegroups.com