ruby on rails - OmniAuth + Pulling Tweets, FB Places, etc -
i'm using omniauth + devise allow users register using facebook/twitter/gowalla/etc attached normal user accounts. when user logs in using of these, or account, social networks attached in authentications table.
i need able pull content of these providers, such tweets or facebook places checkings, etc. understand need use different gem, plugin, whatever getting config need work gems (and make requests) confusing me.
i need able access provider config items in omniauth.rb have api keys , secret keys, etc, need able grab tokens oauth stuff make requests.
other gems https://github.com/jrallison/authlogic_oauth seem store oauth_token, oauth_secret , oauth_token, omniauth not.
as can tell new ruby, rails , oauth, turning out challenging application. needed.
sorted!
added token , secret authentications table described in http://railscasts.com/episodes/236-omniauth-part-2 changed authentication.build line take 2 more parameters:
authentications.build( :provider => omniauth['provider'], :uid => omniauth['uid'], :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'] )
then used code example http://dev.twitter.com/pages/oauth_single_token#ruby
class croncontroller < applicationcontroller def recent_tweets # exchange oauth_token , oauth_token_secret accesstoken instance. def prepare_access_token(oauth_token, oauth_token_secret) consumer = oauth::consumer.new("apikey", "apisecret" { :site => "http://api.twitter.com" }) # create access token object passed values token_hash = { :oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret } access_token = oauth::accesstoken.from_hash(consumer, token_hash ) return access_token end auth = current_user.authentications.find(:first, :conditions => { :provider => 'twitter' }) # exchange our oauth_token , oauth_token secret accesstoken instance. access_token = prepare_access_token(auth['token'], auth['secret']) # use access token agent home timeline response = access_token.request(:get, "http://api.twitter.com/1/statuses/home_timeline.json") render :json => response.body end end
by pulling content current_user.authentications (im finding first should have one) can grab token , security , alllll good.
now can tweak this, stuff saved, faff json , take need. i'm sure facebook pretty similar.
Comments
Post a Comment