我想要實現考拉創業板的Rails應用程序
但我得到一個錯誤「未定義的方法get_access_token」 我的Facebook控制器代碼是`get_access_token未定義的方法」,而在實施考拉寶石Rails應用程序
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
我的存儲訪問令牌模型
class TwitterOauthSetting < ActiveRecord::Base
belongs_to :user
end
我的遷移存儲時的access_token
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
'undefined method get_access_token' for what?請發佈完整的錯誤消息 – Pavan
未定義的方法'get_access_token'爲#。我在這一行中得到了這個錯誤:「FacebookOauthSetting.create({:access_token => @ oauth.get_access_token(params [:code]), :user_id => current_user.id})「 –