Add friends from facebook with Rails 3 + OmniAuth + FBGraph -


i'm trying write add friends step our registration system, , i've been asked implement similar way foursquare works.

it pulls down friends facebook, checks see if of them on foursquare site, , asks if want connect them.

what best way go implementing kind of functionality?

i have seen examples fb js sdk, prefer more integrated approach.

thanks adam

the best way found using devise oauth , fb_graph gems (like specified here , here). had issue versions gemfile configuration looks this:

gem 'devise', :git => 'git://github.com/plataformatec/devise.git' gem 'omniauth', '>=0.2.0.beta' gem 'oa-oauth', :require => 'omniauth/oauth' gem 'fb_graph' 

(my configuration quite old - it's possible devise latest branch supports omniauth in more out-of-the-box way).

my devise initializer:

config.omniauth :facebook_publish, "app_id", "app_secret" 

in user model:

devise :omniauthable 

and

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)   data = access_token['extra']['user_hash']   if user = user.find_by_email(data["email"])     user   else # create user stub password.      user.create(:email => data["email"], :password => devise.friendly_token[0,20])    end end 

in order facebook connect - go path:

user_omniauth_authorize_path(:facebook) 

basically need connection. in order graph use:

 facebook_user = fbgraph::user.new('me', :access_token => access_token['credentials']['token']).fetch 

and friends:

facebook_user.friends 

and that's it. hope helps.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -