Tôi đã sử dụng devise và omniauth-facebook trong ứng dụng Rails 3 của mình để xác thực Facebook, dựa trên hướng dẫn này: Adding Facebook auth to Rails 3.1 app và nó hoạt động tốt!Mã thông báo truy cập từ xác định + xác thực omniauth-facebook để sử dụng trong fb-graph
Nhưng bây giờ tôi muốn tích hợp Facebook đầy đủ trong ứng dụng của mình, tôi có thể truy cập ảnh, bạn bè, v.v. của người dùng và tôi nghĩ đến việc sử dụng fb_graph. fb_graph yêu cầu mã thông báo và tôi muốn biết cách chỉnh sửa mô hình người dùng của mình để lưu mã thông báo và sử dụng nó trong fb_graph. Bất kỳ trợ giúp nào về vấn đề này sẽ được đánh giá cao.
Đây là cách mô hình tài khoản của tôi trông giống như ngay bây giờ:
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
Hãy [xem này] (http://facebook-developer.net/2008/08/ 05/tối ưu hóa cơ sở dữ liệu của bạn-bảng-cho-facebook-connect /). Tạo mô hình 'Facebook' và lưu trữ trong bảng đó nhưng tôi không chắc đó là cách tốt nhất. : P – Rafaiel