![](/img/trans.png)
[英]How to fetch facebook profile data using omniauth-facebook gem?
[英]What is the simplest way to add an profile image with the Omniauth-Facebook Gem?
我正在使用带有Rails的Omniauth Facebook Gem,需要为我的应用程序选择每个用户的个人资料。
是否像使用Gem从facebook检索用户名一样简单,还是需要将其上传到Amazon S3服务器等?
我的用户模型:
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
找不到明确的答案。
更新:在我的展示页面中,它只显示网址:
<b>IMAGE:</b> <%= @user.image %>
谢谢
这很简单。 而且您不需要在服务器上存储图像。 你可以简单地从Facebook上获取它。
我是这样做的:
在User
模型中添加image
字段:
rails generate migration addImageToUsers image:string
添加attr_accessible
列表。
然后在上面的方法中,为图片添加以下列表:
user.image = auth.info.image
这是facebook存储用户图像的直接网址。
您可以inspect
您的auth
哈希来研究不同大小的用户图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.