Omniauth + Devise - 如何从Facebook提取额外的属性?

时间:2014-03-18 03:25:41

标签: ruby-on-rails facebook devise omniauth

这就是我在user.rb中所拥有的......

def apply_omniauth(auth)
#abort(auth.inspect)
# name, :avatar, :tagline, :bio, :phone, :website, :city, :background, :bioextended, :username
# In previous omniauth, 'user_info' was used in place of 'raw_info'

self.email = auth['extra']['raw_info']['email']
self.name = auth['extra']['raw_info']['name'] if auth['extra']['raw_info']['name'].present?
self.city = auth['extra']['raw_info']['location']['name'] if auth['extra']['raw_info']['location'].present?
self.website = auth['extra']['raw_info']['website'] if auth['extra']['raw_info']['website'].present?
#self.username = auth['extra']['raw_info']['username'].parameterize if auth['extra']['raw_info']['username'].present?
self.username = self.id

if auth['info']['image'].present?
  url = "#{auth['info']['image']}?type=large" #.sub!('square', 'large') 
  self.get_avatar(url)
end

 # Again, saving token is optional. If you haven't created the column in authentications table, this will fail
authentications.build(:provider => auth['provider'], :uid => auth['uid'], :token => auth['credentials']['token'])
end

def get_avatar(url)
extname = File.extname(url)
basename = File.basename(url, extname)
file = Tempfile.new([basename, extname])
file.binmode
open(URI.parse(url)) do |data|
  file.write data.read
end
file.rewind
self.avatar = file
end

这是我的范围......

the_scope = 'email, read_stream, read_friendlists, friends_likes, friends_status, offline_access'

它收集姓名,电子邮件,头像和城市。但是,当我试图让它收集额外的属性,如网站和用户喜欢它没有检索它们。

有关如何检索这两个属性的任何想法?

0 个答案:

没有答案