Twitter4R OAuth

Post on 12-May-2015

1.561 views 1 download

Tags:

Transcript of Twitter4R OAuth

Configuring your Twitter4R App with OAuth

Susan Potter(@SusanPotter)

Twitter4R(@t4ruby)

March 2011

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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’

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’

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’

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”)

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”)

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”)

Fin

HTH, if you have more questions:twitter4r-users@googlegroups.com

Fin

HTH, if you have more questions:twitter4r-users@googlegroups.com