我在我的Rails 3应用中使用了devise和omniauth-facebook进行Facebook身份验证,基于本教程:Adding Facebook auth to Rails 3.1 app,它的工作非常棒!从devise + omniauth-facebook身份验证访问令牌在fb-graph中使用
但是现在我想在我的应用程序中使用完整的Facebook集成功能,通过它我可以访问用户的照片,朋友等,为此我正在考虑使用fb_graph。 fb_graph需要一个标记,并且我想知道如何编辑我的用户模型以保存标记并在fb_graph中使用它。任何关于此事的帮助将不胜感激。
这是我的用户模型看起来像现在:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :photos
has_many :scrapbooks
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token.extra.raw_info
if user = User.where(:email => data.email).first
user
else # Create a user with a stub password.
User.create!(:email => data.email, :password => Devise.friendly_token[0,20])
end
end
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"]
end
end
end
end
让我们参考,以创建注释[见这里](http://facebook-developer.net/2008/08/ 05 /优化,你的数据库,表换Facebook的连接/)。 创建'Facebook'模型并存储在该表中,但我不确定这是最好的方法。 :P – Rafaiel 2012-04-10 08:32:17