I want to implement koala gem in rails app
But i am getting an error "undefined method get_access_token' My facebook controller code is
class FacebookController < ApplicationController
before_filter :authenticate_user!
def index
unless current_user.facebook_oauth_setting
@oauth = Koala::Facebook::OAuth.new("app-id", "secret", "http://#{request.host}:#{request.port}/callback")
session["oauth_obj"] = @oauth
redirect_to @oauth.url_for_oauth_code
else
redirect_to "/facebook_profile"
end
end
def callback
unless current_user.facebook_oauth_setting
@oauth = session["oauth_obj"]
Rails.logger.info("**************#{@oauth}***************")
Rails.logger.info("**********#{params[:code]}*************")
FacebookOauthSetting.create({:access_token => @oauth.get_access_token(params[:code]), :user_id => current_user.id})
redirect_to "/facebook_profile"
else
redirect_to "/"
end
end
def facebook_profile
if current_user.facebook_oauth_setting
@graph = Koala::Facebook::API.new(current_user.facebook_oauth_setting.access_token)
@profile = @graph.get_object("me")
@picture = @graph.get_picture("me")
@feed = @graph.get_connections("me","feed")
@friends = @graph.get_connections("me", "friends")
else
redirect_to "/"
end
end
end
My model to store access token is
class TwitterOauthSetting < ActiveRecord::Base
belongs_to :user
end
My migration to store access_token is
class CreateFacebookOauthSettings < ActiveRecord::Migration
def change
create_table :facebook_oauth_settings do |t|
t.string :access_token
t.integer :user_id
t.timestamps null: false
end
end
end
Aucun commentaire:
Enregistrer un commentaire