Twitter4R OAuth

28
Configuring your Twitter4R App with OAuth Susan Potter (@SusanPotter) Twitter4R (@t4ruby) March 2011

Transcript of Twitter4R OAuth

Page 1: Twitter4R OAuth

Configuring your Twitter4R App with OAuth

Susan Potter(@SusanPotter)

Twitter4R(@t4ruby)

March 2011

Page 2: Twitter4R OAuth

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

Page 3: Twitter4R OAuth

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

Page 4: Twitter4R OAuth

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

Page 5: Twitter4R OAuth

In this screencast we will. . .

• set up a new Twitter apphttps://twitter.com/apps/new

• configure consumer tokensevery app has a key and a secret; secret should be ’secret’

• getting access tokens for userapps need to retrieve access tokens for each user

• use access tokensstore access tokens (key and secret) for each user

Page 6: Twitter4R OAuth

In this screencast we will. . .

• set up a new Twitter apphttps://twitter.com/apps/new

• configure consumer tokensevery app has a key and a secret; secret should be ’secret’

• getting access tokens for userapps need to retrieve access tokens for each user

• use access tokensstore access tokens (key and secret) for each user

Page 7: Twitter4R OAuth

In this screencast we will. . .

• set up a new Twitter apphttps://twitter.com/apps/new

• configure consumer tokensevery app has a key and a secret; secret should be ’secret’

• getting access tokens for userapps need to retrieve access tokens for each user

• use access tokensstore access tokens (key and secret) for each user

Page 8: Twitter4R OAuth

In this screencast we will. . .

• set up a new Twitter apphttps://twitter.com/apps/new

• configure consumer tokensevery app has a key and a secret; secret should be ’secret’

• getting access tokens for userapps need to retrieve access tokens for each user

• use access tokensstore access tokens (key and secret) for each user

Page 9: Twitter4R OAuth

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

Page 10: Twitter4R OAuth

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

Page 11: Twitter4R OAuth

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

Page 12: Twitter4R OAuth

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

Page 13: Twitter4R OAuth

Configuring consumer tokens

# In a Rails 2.3 / 3.x app this might be# in: config/initializers/twitter4r.rbTwitter Client.configure do |config|config.oauth_consumer_token = CONSUMER_KEYconfig.oauth_consumer_secret = CONSUMER_SECRET

end

Page 14: Twitter4R OAuth

Configuring consumer tokens

# In a Rails 2.3 / 3.x app this might be# in: config/initializers/twitter4r.rbTwitter Client.configure do |config|config.oauth_consumer_token = CONSUMER_KEYconfig.oauth_consumer_secret = CONSUMER_SECRET

end

Page 15: Twitter4R OAuth

Configuring consumer tokens

# In a Rails 2.3 / 3.x app this might be# in: config/initializers/twitter4r.rbTwitter Client.configure do |config|config.oauth_consumer_token = CONSUMER_KEYconfig.oauth_consumer_secret = CONSUMER_SECRET

end

Page 16: Twitter4R OAuth

Configuring consumer tokens

# In a Rails 2.3 / 3.x app this might be# in: config/initializers/twitter4r.rbTwitter Client.configure do |config|config.oauth_consumer_token = CONSUMER_KEYconfig.oauth_consumer_secret = CONSUMER_SECRET

end

Page 17: Twitter4R OAuth

Getting access tokens for a user, [1/2]

# Using OAuth Ruby gem library helper in:# app/controller/application_controller.rbdef redirect_to_twitterconsumer = OAuth Consumer.new KEY, SECRET,

:site => “https://twitter.com”token = consumer.get_request_tokenredirect_to(token.authorize_url)

end

Page 18: Twitter4R OAuth

Getting access tokens for a user, [1/2]

# Using OAuth Ruby gem library helper in:# app/controller/application_controller.rbdef redirect_to_twitterconsumer = OAuth Consumer.new KEY, SECRET,

:site => “https://twitter.com”token = consumer.get_request_tokenredirect_to(token.authorize_url)

end

Page 19: Twitter4R OAuth

Getting access tokens for a user, [1/2]

# Using OAuth Ruby gem library helper in:# app/controller/application_controller.rbdef redirect_to_twitterconsumer = OAuth Consumer.new KEY, SECRET,

:site => “https://twitter.com”token = consumer.get_request_tokenredirect_to(token.authorize_url)

end

Page 20: Twitter4R OAuth

Getting access tokens for a user, [1/2]

# Using OAuth Ruby gem library helper in:# app/controller/application_controller.rbdef redirect_to_twitterconsumer = OAuth Consumer.new KEY, SECRET,

:site => “https://twitter.com”token = consumer.get_request_tokenredirect_to(token.authorize_url)

end

Page 21: Twitter4R OAuth

Getting access tokens for a user, [2/2]

# Using OAuth Ruby gem library in:# app/controller/oauth_controller.rbdef createprovider = params[:provider]case providerwhen ’twitter’

# bla bla blaend

end# Remember to add the routes:match ’oauth/:provider/callback’ => ’oauth#create’

Page 22: Twitter4R OAuth

Getting access tokens for a user, [2/2]

# Using OAuth Ruby gem library in:# app/controller/oauth_controller.rbdef createprovider = params[:provider]case providerwhen ’twitter’

# bla bla blaend

end# Remember to add the routes:match ’oauth/:provider/callback’ => ’oauth#create’

Page 23: Twitter4R OAuth

Getting access tokens for a user, [2/2]

# Using OAuth Ruby gem library in:# app/controller/oauth_controller.rbdef createprovider = params[:provider]case providerwhen ’twitter’

# bla bla blaend

end# Remember to add the routes:match ’oauth/:provider/callback’ => ’oauth#create’

Page 24: Twitter4R OAuth

Using access tokens

# Pass in access key/secret tokens to# Twitter Client.new call for each userclient = Twitter Client.new :oauth_access => {

:key => ACCESS_KEY,:secret => ACCESS_SECRET }

client.status(:post, “Tweet from my OAuth-ed app”)

Page 25: Twitter4R OAuth

Using access tokens

# Pass in access key/secret tokens to# Twitter Client.new call for each userclient = Twitter Client.new :oauth_access => {

:key => ACCESS_KEY,:secret => ACCESS_SECRET }

client.status(:post, “Tweet from my OAuth-ed app”)

Page 26: Twitter4R OAuth

Using access tokens

# Pass in access key/secret tokens to# Twitter Client.new call for each userclient = Twitter Client.new :oauth_access => {

:key => ACCESS_KEY,:secret => ACCESS_SECRET }

client.status(:post, “Tweet from my OAuth-ed app”)

Page 27: Twitter4R OAuth

Fin

HTH, if you have more questions:[email protected]

Page 28: Twitter4R OAuth

Fin

HTH, if you have more questions:[email protected]