我有一個Rails應用程序,用戶可以通過Facebook登錄oauth。Rails:facebook oauth:獲取用戶個人資料鏈接
我檢索他們的圖像,電子郵件和名稱。我想要做的是取消他們的個人資料鏈接(http://facebook.com/name),性別(男性,女性,其他)
,但它不爲鏈接和性別的工作,這是我的集成:
的Gemfile
gem 'omniauth-facebook'
User.rb模式
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.name = auth.info.name # assuming the user model has a name
user.image = auth.info.image # assuming the user model has an image
user.gender = auth.info.gender # assuming the user model has a gender
user.link = auth.info.link # assuming the user modal has a link
end
end
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
end
end
end
編輯
devise.rb
config.omniauth :facebook, "***", "***"
但對於 '零'
任何想法我可能會錯過所有的用戶,性別和鏈接的回報嗎?
感謝
嘗試檢查認證後由omniauth返回的'auth' hash的值ñ。看看散列是否有返回的值。如果沒有,那將是因爲該特定用戶的隱私設置。 – Alfie
它返回零,但我嘗試了一個完全打開的配置文件,哈希也是零。但我認爲鏈接價值是公衆形象的一部分,這意味着它不能被用戶隱藏......無論他的個人資料多麼私密。 – zacchj
您是否檢查auth散列返回?它的結構以及如何存在其他字段等。 – Alfie