OmniAuth + pulling tweets, FB places, etc.

I am using OmniAuth + Devise so that users can register using Facebook / Twitter / Gowalla / etc connected to regular user accounts. Now, when a user logs in using any of them or their account, all their social networks are attached to the authentication table.

I need to be able to extract content from any of these providers, for example, their tweets or their checks on Facebook, etc. I understand that I will need to use another gem, a plugin, to do this, but the config I need to work with these gems (and make requests) is confusing.

I need to have access to provider configuration items in omniauth.rb, so I have API keys and secret keys, etc., then I need to be able to grab tokens from oAuth stuff to make requests.

Other gems such as https://github.com/jrallison/authlogic_oauth seem to store oauth_token, oauth_secret and oauth_token, but OmniAuth does not.

As you can probably say, I'm very new to Ruby, Rails, and oAuth, so this turned out to be a very complicated application. Help is very necessary.

+6
ruby-on-rails ruby-on-rails-3 omniauth ruby-on-rails-plugins
source share
2 answers

Sorted!

Added the token and secret of the authentication table described in http://railscasts.com/episodes/236-omniauth-part-2 , but changed the authentication.build line to get two more parameters:

authentications.build( :provider => omniauth['provider'], :uid => omniauth['uid'], :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'] ) 

then used the sample code from http://dev.twitter.com/pages/oauth_single_token#ruby

 class CronController < ApplicationController def recent_tweets # Exchange your oauth_token and oauth_token_secret for an AccessToken instance. def prepare_access_token(oauth_token, oauth_token_secret) consumer = OAuth::Consumer.new("APIKey", "APISecret" { :site => "http://api.twitter.com" }) # now create the access token object from 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 and oauth_token secret for the AccessToken instance. access_token = prepare_access_token(auth['token'], auth['secret']) # use the access token as an agent to get the home timeline response = access_token.request(:get, "http://api.twitter.com/1/statuses/home_timeline.json") render :json => response.body end end 

By pulling the contents from current_user.authentications (im discovering the first, since they should only have one), I can capture the token and security and its alllll.

Now I can configure this, get things saved, faff with JSON and take what I need. I'm sure Facebook will be very similar.

+20
source share

Is this what you are looking for? http://railscasts.com/episodes/236-omniauth-part-2 :) It shows how to retrieve data such as email. Not sure if this is what you are looking for.

+6
source share

All Articles