The best way I've found is to use devess with oauth and fb_graph gems (as stated here and here ). I had a versioning issue, so my gemfile configuration looks like 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 is quite old - it is possible that the development of the last branch now supports omniauth in a more finished form). A.
my initializer:
config.omniauth :facebook_publish, "APP_ID", "APP_SECRET"
In your 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
To connect to facebook, go along the path:
user_omniauth_authorize_path(:facebook)
Basically, this is all you need to connect. To get the graph, I now use:
facebook_user = FbGraph::User.new('me', :access_token => access_token['credentials']['token']).fetch
And for friends:
facebook_user.friends
What is it. Hope this helps.
krakover
source share