我正在使用 omniauth-linkedin gem 来允许用户使用他们的 LinkedIn 帐户登录到我的 Rails 应用程序。我目前正在使用 auth.info.image
来存储用户的 LinkedIn 个人资料图像 URL:
用户.rb
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.email = auth.info.email
user.linkedin_photo_url = auth.info.image
user.password = Devise.friendly_token[0,20]
end
但是,图像非常小 (50x50)。除了 auth.info.image 之外,还有其他方法可以用来提取用户主页上的大型个人资料图片吗?
谢谢!
编辑:我正在使用 omniauth-linkedin
和 omniauth
gem。看起来 linkedin
gem 有一个方法,可以选择确定图像大小,但我正在努力使用 omniauth-linkedin gem 实现它。本自述文件解释说这是可能的,但解释缺少一些细节。有人可以帮我解决这个问题吗?
https://github.com/skorks/omniauth-linkedin#using-it-with-the-linkedin-gem
最佳答案
我知道已经有一段时间了,但我只是在找这个,我想我会把它留在这里。解决方案很好,但会导致额外调用。 Omniauth 已经在获取配置文件,所以我们只需要告诉它也获取原始图片
linkedin_options = {
scope: 'r_fullprofile r_emailaddress',
fields: ['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url', "picture-urls::(original)"]
}
provider :linkedin, app_id,app_secret, linkedin_options
pictureUrls
将在额外信息中可用。
要获取图像,请使用auth_hash[:extra][:raw_info][:pictureUrls][:values].first
关于ruby-on-rails - 带有 omniauth linkedin Ruby gem 的大型个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22572868/