如何使用omniauth和devise保存Facebook名称
我试图在保存 Facebook 用户时保存该用户的姓名,但我似乎无法做到这一点。我已遵循 devise github 上的指南,并且与 Facebook 的集成有效美好的;用户的电子邮件按预期保存。但是,我不知道如何保存用户名。现在,我这样做:
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token['extra']['user_hash']
if user = User.find_by_email(data["email"])
user
else # Create a user with a stub password.
User.create(:email => data["email"], :name => data["name"], :password => Devise.friendly_token[0,20])
end
end
但这不起作用。我做错了什么吗?
I'm trying to save the name of a Facebook user upon saving that user, but I don't seem to be able to. I have followed the guides on the devise github and the integration with Facebook works fine; the users email is saved as is to be expected. However, I can't figure out how to save the users name. Right now, I do this:
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token['extra']['user_hash']
if user = User.find_by_email(data["email"])
user
else # Create a user with a stub password.
User.create(:email => data["email"], :name => data["name"], :password => Devise.friendly_token[0,20])
end
end
but that doesn't work. Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
似乎 Auth 哈希模式发生了很大变化:
https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
Seems like Auth hash schema has changed a lot:
https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
用户名存储在:
如果这不是您需要的,我建议您检查 access_token 的内容。
The users name is stored in:
If that is not what you need, I suggest you inspect the contents of the access_token.