Reputation: 4464
I'm making a Rails 4 site for Facebook Canvas using Koala gem. I tried to follow this Koala on Rails guide but always result with nil
in the facebook_token
.
Here's my controller (the same as in the guide):
# app/controllers/application_controller.rb
def facebook_cookies
@facebook_cookies ||= Koala::Facebook::OAuth.new.get_user_info_from_cookie(cookies)
end
# app/controllers/photos_controller.rb
def index
...
@access_token = facebook_cookies['access_token']
@graph = Koala::Facebook::GraphAPI.new(@access_token)
...
end
I got this error on the line that calls facebook_cookies
undefined method `[]' for nil:NilClass
I figure that when I call .get_user_info_from_cookie(cookies)
, the cookies
is never declared before.
The doc doesn't mention anything about how to obtain that variable. Any help?
Thanks
Upvotes: 2
Views: 248
Reputation: 642
I had the same problem. It turned out, that the cookies have never been set.
For setting the cookies, you need the Facebook Javascript SDK
afterwards you need something like this in your JS:
window.fbAsyncInit = function() {
return FB.init({
appId: YOUR_FACEBOOK_APP_ID,
cookie: true
});
};
Upvotes: 2