Tuesday, November 25, 2014

Integrating facebook using koala gem

In view:

<div id=”fb-root”></div>
<script src=”http://connect.facebook.net/en_US/all.js”&gt;
</script>
<script>
FB.init({
appId:’204597759582691′, cookie:true,
status:true, xfbml:true
});
</script>
<fb:login-button v=”2″ size=”xlarge” length=”long”
perms=”email” onlogin=’window.location = “/app/code”‘ >
Login with Facebook
</fb:login-button>
<div>
<a href=””>signin facebook</a>
</div>

In Controller:

class AppController < ApplicationController
def code
“set_facebook_client” #to check whether the user already login with the face book
oauth = Koala::Facebook::OAuth.new(204597759582691, “df14fdac2d0ebf6fbf684c68b2009ef8″)
#~ oauth = Koala::Facebook::OAuth.new(appid, “appsecretkey”)
@facebook_client ||= if @facebook_cookies = oauth.get_user_info_from_cookies(cookies)
Koala::Facebook::GraphAPI.new(@facebook_cookies[‘access_token’])
end
profile = @facebook_client.get_object(“me”)
end
end


In gemfile:
gem ‘koala’

No comments:

Post a Comment