脸书用户2。 Rails 并创建新用户
我想使用 facebooker2 来实现 facebook 连接功能。因此,当用户使用 Facebook 凭据登录时,我想重定向到操作 create_facebook_user
。
所以我使用了facebooker2的这个助手:
<%= fb_login_and_redirect("/users/create_facebook_user", :perms => 'first_name,last_name,email,user_birthday') %>
可以吗?我如何访问 facebook 公共信息,如电子邮件、名字、姓氏等。
我的控制器是:
def create_facebook_user
if current_facebook_user
@user = User.find_by_fb_user_id(current_facebook_user.id.to_i)
end
if @user.blank?
@facebook_user = current_facebook_user.fetch
@user = User.create :login => @facebook_user.email, :email => @facebook_user.email, :name => @facebook_user.name, :fb_user_id => @facebook_user.id
if @user.save
@user.profile = Profile.create(:benefactor_id => nil, :benefactor_invites => Setting.find_by_identifier("benefactor_invites").value.to_i)
redirect_to :controller => "profiles", :action => "show", :id => @user.profile.id
else
render "new"
end
elsif @user.fb_user_id.nil?
@user.update_attribute :fb_user_id, current_facebook_user.id
redirect_to :controller => "dashboard", :url => "index"
else
redirect_to :controller => "dashboard", :url => "index"
end
end
好的,我的问题是获取用户 facebook 信息。
I want to user facebooker2 for facebook connect functionality. So when the user login with facebook credentials i want to redirect to action create_facebook_user
.
So I used this helper of facebooker2:
<%= fb_login_and_redirect("/users/create_facebook_user", :perms => 'first_name,last_name,email,user_birthday') %>
OK? How can i access to facebook public information as email, first_name, last_name, etc.
My controller is:
def create_facebook_user
if current_facebook_user
@user = User.find_by_fb_user_id(current_facebook_user.id.to_i)
end
if @user.blank?
@facebook_user = current_facebook_user.fetch
@user = User.create :login => @facebook_user.email, :email => @facebook_user.email, :name => @facebook_user.name, :fb_user_id => @facebook_user.id
if @user.save
@user.profile = Profile.create(:benefactor_id => nil, :benefactor_invites => Setting.find_by_identifier("benefactor_invites").value.to_i)
redirect_to :controller => "profiles", :action => "show", :id => @user.profile.id
else
render "new"
end
elsif @user.fb_user_id.nil?
@user.update_attribute :fb_user_id, current_facebook_user.id
redirect_to :controller => "dashboard", :url => "index"
else
redirect_to :controller => "dashboard", :url => "index"
end
end
OK, my problem is to obtain user facebook information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,请注意您正在使用的一些扩展权限不存在:“first_name”和“last_name”。查看有关扩展权限的 Facebook 页面。
使用 Facebooker 登录后,您可以像这样访问这些字段:
First of all, note that some of the extended permissions you are using do not exist: "first_name" and "last_name". Check the Facebook page about extended permissions.
Once logged in with Facebooker, you can access these fields like this: