Topic: Facebook Intergration
I am currently in the Process of creating a new Framework Application about a Stadium Tours Website and was wondering if it was possible to integrate Facebook into the site?
Thanks in Advance.
You are not logged in. Please login or register.
Rails Forum - Ruby on Rails Help and Discussion Forum » Other Rails Programming » Facebook Intergration
I am currently in the Process of creating a new Framework Application about a Stadium Tours Website and was wondering if it was possible to integrate Facebook into the site?
Thanks in Advance.
What do you mean by integrating facebook?.
if i am getting you right,
Just register you app at developers.facebook.com and get your user id and secret key. Use oauth2 and graph api of facebook to retrieve details of all the users who have added your page(my preferable choice is omniauth gem). This is just a brief intro, just dig yourself into the Graph API documentation of facebook to get to know the extent of which you can retrieve info. Hope this helps you.
Someone else may be able to point you at the perfect gem for this, but I can tell you that I've worked on a similar problem and it wasn't much work to roll our own, based on the oauth2 gem.
Here's a sketch of the code/flow I use.
1) User clicks on 'Connect to Facebook' and this sends you to an action like this
def to_facebook
options = {
:redirect_uri => facebook_callback_url,
:scope => "email,publish_stream" # whatever you want to do
}
client = OAuth2::Client.new(FACEBOOK_API_KEY, FACEBOOK_API_SECRET, :site => FACEBOOK_API_SITE)
redirect_to client.web_server.authorize_url(options)
end
2) User goes over to facebook and gives you all the access you want, then facebook calls the callback you specified facebook_callback_url which should take you to an action like this:
def facebook_callback
client = OAuth2::Client.new(FACEBOOK_API_KEY, FACEBOOK_API_SECRET, :site => FACEBOOK_API_SITE)
access_token = client.web_server.get_access_token(params[:code], :redirect_uri => facebook_callback_url)
do_my_custom_user_association(access_token)
end
Then you can specify whatever you want in do_my_custom_user_association, you should have a current_user available from authlogic if someone is logged in, so you can redirect to a flow that lets the logged in user select if they want to merge into their current account or a different one. If there's no current user, you can send them to a create account flow, with some facebook data attached.
Note that this is just a sketch, there are error cases to handle (e.g. facebook_callback will be hit with the param error_reason if the get_acccess_token fails) and I'm not recommending you do all the oauth2 interaction right in your controller, but the basic idea is there.
Hosting provided by aTech Media