Ruby Twitter how to authorize user? -



Ruby Twitter how to authorize user? -

i have app must tweet in user's page.

using gem twitter

i have action must create stuff.

def phone call client = set_client client.token client.update!("i'm tweeting @gem!") end

this method create client using api

def set_client twitter::rest::client.new |config| config.consumer_key = "****" config.consumer_secret = "****" config.access_token = "****" config.access_token_secret = "****" end end

if think right need user's access_token , authorize him permissions. in app's setting can token page only.

how can realize feature, when i'm getting user's access_token , access_token_secret?

to access token , secret user, need finish twitter's 3-legged authorization.

gem omniauth-twitter makes process easy, , explained in nice railscasts tutorial

assuming have omniauth configured , userscontroller with:

def create user = user.from_omniauth(env["omniauth.auth"]) end

then in user model:

def self.from_omniauth(auth) where(auth.slice("provider", "uid")).first || create_from_omniauth(auth) end def self.create_from_omniauth(auth) create! |user| user.provider = auth["provider"] user.uid = auth["uid"] user.name = auth["info"]["nickname"] user.access_token = auth["credentials"]["token"] user.access_token_secret = auth["credentials"]["secret"] end end def set_client twitter::rest::client.new |config| config.consumer_key = "****" config.consumer_secret = "****" config.access_token = access_token config.access_token_secret = access_token_secret end end

ruby ruby-on-rails-4 twitter

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -